-
-
Save msf/922fc7a0d44b5723ac27fa12130eab05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from values.app import App | |
from repository.sqlalchemy.entities import DBApp | |
from repository.sqlalchemy.sessions import Session | |
def find_app_by_id(app_id): | |
db_app = DBApp.query.get(id=app_id) | |
if not db_app: | |
return None | |
app = App.from_database(db_app) | |
return app | |
def find_app_by_name(name): | |
db_app = DBApp.query.get(name=name) | |
if not db_app: | |
return None | |
return App.from_database(db_app) | |
def create_app(name, description): | |
""" idempotently create an App under a transaction, the names are unique """ | |
with Session() as session: | |
app = find_app_by_name(name) | |
if app: | |
return app | |
db_app = DBApp.create(name=name, description=description) | |
return App.from_database(db_app) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment