def insert_a_package(): p = Package() p.id = input('Package id / name: ').strip().lower() p.summary = input('Package summary: ').strip() p.author_name = input('Author: ').strip() p.license = input('License: ').strip() print('Release 1:') r = Release() r.major_ver = int(input('Major Version: ')) r.minor_ver = int(input('Minor Version: ')) r.build_ver = int(input('Build Version: ')) r.size = int(input('Size in bytes: ')) p.releases.append(r) print('Release 2:') r = Release() r.major_ver = int(input('Major Version: ')) r.minor_ver = int(input('Minor Version: ')) r.build_ver = int(input('Build Version: ')) r.size = int(input('Size in bytes: ')) p.releases.append(r) session = db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p = Package() p.id = input("package id").strip().lower() p.summary = input("sum").strip() p.author_name = input("name").strip() p.license = input("licence").strip() print("Release 1") r = Release() r.major_ver = int(input("int").strip()) r.minor_ver = int(input("int").strip()) r.build_ver = int(input("int").strip()) r.size = int(input("int").strip()) p.releases.append(r) print("Release 2") r = Release() r.major_ver = int(input("int").strip()) r.minor_ver = int(input("int").strip()) r.build_ver = int(input("int").strip()) r.size = int(input("int").strip()) p.releases.append(r) session = db_session.factory() session.add(p) session.commit()
def insert_a_package(): p = Package() p.id = input('Package id / name: ').strip().lower() p.summary = input("Package summary: ").strip() p.author_name = input("Author: ").strip() p.license = input("License: ").strip() print("Release 1: ") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) r.size = int(input("Size in bytes: ")) p.releases.append(r) print("Release 2: ") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) r.size = int(input("Size in bytes: ")) p.releases.append(r) session = db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p=Package() p.id=input("Package ID/Name:").strip().lower() p.summary=input("Summary: ").strip() p.license=input("Licence").strip() p.author_name=input("Author name").strip() print("Release 1") r=Release() r.major_ver=int(input("Major Version")) r.minor_ver=int(input("Minor Version")) r.build_ver=int(input("Build")) r.size=int(input("Size:")) p.releases.append(r) print("Release 2") r = Release() r.major_ver = int(input("Major Version")) r.minor_ver = int(input("Minor Version")) r.build_ver = int(input("Build")) r.size = int(input("Size:")) p.releases.append(r) session=db_session.create_session() session.add(p) session.commit()
def insert_a_package(): p = Package() p.id = input("Package id / name: ").strip().lower() p.summary = input("Package summary: ").strip() p.author_name = input("Author: ").strip() p.license = input("License: ").strip() print("Release 1:") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) # this attaches the relationship with r to the Package p. sa will traverse this object and see this relationship # and know it must add r even if we don't explicitly do a session.add(r) here. Adding r here might be awkward since # we might have an auto generated p.primary_key, etc... p.releases.append(r) # if we want a second release object, we can do the same thing and again append to p.releases print("Release 2:") r = Release() r.major_ver = int(input("Major version: ")) r.minor_ver = int(input("Minor version: ")) r.build_ver = int(input("Build version: ")) p.releases.append(r) session = db_session.create_session() # # Old way (before we had a db_session.create_session()). Old way also had no type hinting # # If you want to see what the session object can do, you can use type casting # import sqlalchemy.orm as orm # session: orm.Session = db_session.__factory() # # Now type session <dot> <tab> and everything is available! # Add the changes we want to commit to the db (don't need to add r's because of the relations we already appended) session.add(p) # Once we have changes to commit (all at once), do a commit session.commit()