async def create_exam(node_type: str, name: str = Form(...)): klass = globals()[node_type] instance = klass(name) session = session_factory() session.add(instance) session.commit() return {"id": instance.id, "name": instance.name}
def test_db(): session = session_factory() cur = session.execute( "select icao, latitude, longitude, iata from Airport where iata = 'GKA'" ) cur = cur.fetchone() assert cur[0] == 'AYGA'
async def create_node(node_type: str, path: str, name: str = Form(...), child_node_type: str = Form(...)): session = session_factory() klass = globals()[node_type] path_tokens = path.split('/') node = session.query(klass).get(path_tokens[0]) leaf_node = get_node(node, path_tokens[1:]) print(child_node_type) klass2 = globals()[child_node_type] new_node = klass2(name) leaf_node.append_child(new_node) session.commit() return new_node.id
async def get_all(): session = session_factory() exam_query = session.query(Exam) return exam_query.all()
async def get_all(): session = session_factory() exam_query = session.query(Exam) return list_to_json(exam_query.all())
async def get_node(type, node_id): session = session_factory() klass = globals()[type] node = session.query(klass).get(node_id) return node.json()
def inner(*args, **kwargs): g.session = session_factory() return func(*args, **kwargs)