def section_by_id(cls, sec_id): session = DbSessionFactory.create_session() section = session.query(Section).filter( Section.sec_id == sec_id).first() session.close() return section
def get_documents_sections(cls,doc_id,limit=None): session = DbSessionFactory.create_session() # query = session.query(Group) docs = [] for d, g, s in session.query(Document, Group, Section).\ filter(Document.doc_id == Group.doc_id,\ Section.sec_id == Group.sec_id,\ Document.doc_id == doc_id).all(): print("group_id: {} doc_name: {} text: {}".format(g.group_id, d.doc_name, s.sec_text)) u = Doc_Group_Sec() u.add_group_id(g.group_id) u.add_doc_name(d.doc_name) u.add_doc_id(d.doc_id) u.add_sec_text(s.sec_text) u.add_sec_id(s.sec_id) u.add_order(g.order) docs.append(u.to_dict()) # docs = session.query(Document, Group, Section).\ # filter(Document.doc_id == Group.doc_id,\ # Section.sec_id == Group.sec_id, \ # Document.doc_id == doc_id).all() # if limit: # groups = query[:limit] # else: # groups = query.all() session.close() return docs
def doc_by_name(cls, doc_name): session = DbSessionFactory.create_session() document = session.query(Document).filter( Document.doc_name == doc_name).first() session.close() return document
def main(): DbSessionFactory.global_init('myDocuments.sqlite') # (test_call_groups()) # test_call_documents() # test_get_all_documents() # (test_doc()) # test_create_doc('abc') # test_update_doc('abc') # TEST DOCUMENTS # test_create_doc() # TEST SECTIONS # test_create_section() # test_get_all_sections() # test_get_sections_by_doc('d60a7e19-6c2c-4d90-92c9-cb8fb6c189a0') # test_edit_section() # TEST GROUPS # for t in range(1,250): # test_create_group(str(t)) # test_get_doc_group() # TEST DOC_PARENT # test_create_doc_parent() # test_get_doc_parent_report() # test_find_parent_child() # # for _ in range(1,20): # test_create_doc_group_relationships() # # for _ in range(1,6): # test_create_multiple_doc_parents() # # for _ in range (1,50000): # r = 5 # t = 4 # u = r/t # print(u) test_create_multiple_docs() # test_get_doc_by_name() print('done')
def delete_group(cls, group_id): session = DbSessionFactory.create_session() db_group = session.query(Group).filter(Group.group_id == group_id).first() if not db_group: return session.delete(group_id) session.commit()
def delete_section(cls, sec_id): session = DbSessionFactory.create_session() db_section = session.query(Section).filter( Section.sec_id == sec_id).first() if not db_section: return session.delete(sec_id) session.commit()
def update_document(cls, doc_data): session = DbSessionFactory.create_session() db_doc = session.query(Document).filter( Document.doc_id == doc_data.doc_id).first() db_doc.doc_name = doc_data.doc_name session.commit() return db_doc
def delete_document(cls, doc_id): session = DbSessionFactory.create_session() db_doc = session.query(Document).filter( Document.doc_id == doc_id).first() if not db_doc: return session.delete(doc_id) session.commit()
def all_sections(cls, limit=None): session = DbSessionFactory.create_session() query = session.query(Section) if limit: sections = query[:limit] else: sections = query.all() session.close() return sections
def all_groups(cls,limit=None): session = DbSessionFactory.create_session() query = session.query(Group) if limit: groups = query[:limit] else: groups = query.all() session.close() return groups
def update_group(cls, group_data): try: session = DbSessionFactory.create_session() db_group = session.query(Group).filter(Group.group_id == group_data.group_id).first() db_group.doc_id = group_data.doc_id db_group.sec_id = group_data.sec_id session.commit() return db_group except Exception as e: print(e)
def all_documents(cls, limit=None): session = DbSessionFactory.create_session() query = session.query(Document). \ order_by(Document.doc_name) if limit: documents = query[:limit] else: documents = query.all() session.close() return documents
def update_section(cls, section_data): try: session = DbSessionFactory.create_session() db_section = session.query(Section).filter( Section.sec_id == section_data.sec_id).first() db_section.sec_text = section_data.sec_text db_section.sec_date_in = parse(section_data.sec_date_in) session.commit() return db_section except Exception as e: print(e)
def add_document(cls, doc): try: session = DbSessionFactory.create_session() db_doc = Document() db_doc.doc_id = doc.doc_id db_doc.doc_name = doc.doc_name session.add(db_doc) session.commit() return db_doc except Exception as e: print(e)
def add_section(cls, section): try: session = DbSessionFactory.create_session() db_section = Section() # db_section.sec_id = section.sec_id db_section.sec_text = section.sec_text db_section.sec_date_in = parse(section.sec_date_in) session.add(db_section) session.commit() return db_section except Exception as e: print(e)
def add_group(cls,group): try: session = DbSessionFactory.create_session() db_group = Group() # db_section.sec_id = section.sec_id db_group.doc_id = group.doc_id db_group.sec_id = group.sec_id db_group.order = 1 session.add(db_group) session.commit() return db_group except Exception as e: print (e)
def create_doc_parent(cls, doc_parent): try: session = DbSessionFactory.create_session() db_doc_parent = DocumentParent() # db_doc_parent.doc_parent_id = doc_parent['doc_parent_id'] db_doc_parent.doc_id = doc_parent['doc_id'] db_doc_parent.parent_id = doc_parent['parent_id'] db_doc_parent.relationship = doc_parent['relationship'] session.add(db_doc_parent) session.commit() return db_doc_parent except Exception as e: print(e)
def doc_parent_by_doc_id(cls, doc_id): session = DbSessionFactory.create_session() # section = session.query(Section).filter(Section.sec_id == sec_id).first() u = 0 docs = [] # for dp, d1a, d2a in session.query(DocumentParent, d1, d2).\ # filter(DocumentParent.doc_id == d1.doc_id,\ # DocumentParent.parent_id == d2.doc_id).all(): # # d2.doc_id == doc_id).all(): # for dp, d1a, d2a in session.query(DocumentParent, d1, d2). \ # filter(DocumentParent.doc_id == d1.doc_id,\ # DocumentParent.parent_id == d2.doc_id).all(): q = ( session.query(DocumentParent, Document, Document).filter( DocumentParent.doc_id == Document.doc_id).filter( DocumentParent.parent_id == Document.doc_id) # .filter(User.email == 'someemail') .all()) u = u + 1 # print("relationship: {} doc_name: {} doc_name: {}".format(dp.relationship, d1a.doc_name)) print("relationship: {} doc_name: {} doc_name: {}".format( DocumentParent.relationship, d1.doc_name, d2.doc_name)) # # u = Doc_Group_Sec() # # u.add_group_id(g.group_id) # u.add_doc_name(d.doc_name) # u.add_sec_text(s.sec_text) # u.add_sec_id(s.sec_id) # # docs.append(u.to_dict()) session.close() return u # docs
def main(): DbSessionFactory.global_init('myDocuments.sqlite') run_it()
def group_by_id(cls, group_id): session = DbSessionFactory.create_session() group = session.query(Group).filter(Group.group_id == group_id).first() session.close() return group
def section_by_doc(cls, doc_id): session = DbSessionFactory.create_session() section = session.query(Group).filter(Group.doc_id == doc_id).all() session.close() return section
def init_db(config): settings = config.get_settings() db_file = settings.get('db_filename') DbSessionFactory.global_init(db_file)