def createSourceType(key): creator = alchemySessionCreator() session = creator() assert isinstance(session, Session) if not session.query(exists().where(SourceTypeMapped.Key == key)).scalar(): sourceTypeDb = SourceTypeMapped() sourceTypeDb.Key = key session.add(sourceTypeDb) session.commit() session.close()
def createSourceType(key): creator = alchemySessionCreator() session = creator() assert isinstance(session, Session) try: session.query(SourceTypeMapped.id).filter(SourceTypeMapped.Key == key).one()[0] except NoResultFound: typ = SourceTypeMapped() typ.Key = key typ.IsAvailable = True session.add(typ) session.commit() session.close()