Here are the examples of the python api sqlalchemy.orm.Session taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1599 Examples
3
Source : models.py
with GNU General Public License v3.0
from bcollazo
with GNU General Public License v3.0
from bcollazo
def database_session():
"""Can use like:
with database_session() as session:
game_states = session.query(GameState).all()
"""
database_url = os.environ.get(
"DATABASE_URL",
"postgresql://catanatron:[email protected]:5432/catanatron_db",
)
engine = create_engine(database_url)
session = Session(engine)
try:
yield session
finally:
session.expunge_all()
session.close()
def upsert_game_state(game, session_param=None):
3
Source : __init__.py
with GNU General Public License v2.0
from christoph2
with GNU General Public License v2.0
from christoph2
def __init__(self, filename = ":memory:", debug = False, logLevel = 'INFO', create = True):
if filename == ':memory:':
self.dbname = ""
else:
if not filename.lower().endswith(DB_EXTENSION):
self.dbname = "{}.{}".format(filename, DB_EXTENSION)
else:
self.dbname = filename
self._engine = create_engine("sqlite:///{}".format(self.dbname), echo = debug,
connect_args={'detect_types': sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES}, native_datetime = True)
self._session = orm.Session(self._engine, autoflush = False, autocommit = False)
self._metadata = model.Base.metadata
if create == True:
model.Base.metadata.create_all(self.engine)
self.session.flush()
self.session.commit()
self.logger = Logger(__name__, level = logLevel)
@classmethod
3
Source : tags.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def after_delete(
cls,
mapper: Mapper,
connection: Connection,
target: Union["Dashboard", "FavStar", "Slice"],
) -> None:
# pylint: disable=unused-argument
session = Session(bind=connection)
# delete row from `tagged_objects`
session.query(TaggedObject).filter(
TaggedObject.object_type == cls.object_type,
TaggedObject.object_id == target.id,
).delete()
session.commit()
class ChartUpdater(ObjectUpdater):
3
Source : tags.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def after_insert(
cls, mapper: Mapper, connection: Connection, target: "FavStar"
) -> None:
# pylint: disable=unused-argument
session = Session(bind=connection)
name = "favorited_by:{0}".format(target.user_id)
tag = get_tag(name, session, TagTypes.favorited_by)
tagged_object = TaggedObject(
tag_id=tag.id,
object_id=target.obj_id,
object_type=get_object_type(target.class_name),
)
session.add(tagged_object)
session.commit()
@classmethod
3
Source : core.py
with Apache License 2.0
from codemation
with Apache License 2.0
from codemation
async def count(cls) -> int:
table = cls.get_table()
database = cls.__metadata__.database
session = Session(database.engine)
sel = session.query(func.count()).select_from(table)
results = await database.fetch(sel.statement, {cls.__name__})
return results[0][0] if results else 0
@classmethod
3
Source : 14d53fa0c9c8_.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
# pass
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='kambuledoctoral2020').first()
app_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
session.query(Question).filter_by(application_form_id=app_form.id).delete()
session.query(Section).filter_by(application_form_id=app_form.id).delete()
session.query(ApplicationForm).filter_by(event_id=event.id).delete()
session.query(Event).filter_by(key='kambuledoctoral2020').delete()
session.commit()
3
Source : 1afd8dfc8d05_add_neuro_imbizo_org.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
session.query(Organisation).filter_by(name='IBRO-Simons Computational Neuroscience Imbizo').delete()
session.commit()
3
Source : 1c3fda18bad6_.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='indaba2020').first()
app_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
op.get_bind().execute("""UPDATE Section SET depends_on_question_id=NULL WHERE application_form_id={}""".format(app_form.id))
session.query(Question).filter_by(application_form_id=app_form.id).delete()
session.query(Section).filter_by(application_form_id=app_form.id).delete()
session.query(ApplicationForm).filter_by(event_id=event.id).delete()
session.query(Event).filter_by(key='indaba2020').delete()
session.commit()
op.get_bind().execute("""SELECT setval('event_id_seq', (SELECT max(id) FROM event));""")
op.get_bind().execute("""SELECT setval('application_form_id_seq', (SELECT max(id) FROM application_form));""")
op.get_bind().execute("""SELECT setval('section_id_seq', (SELECT max(id) FROM section));""")
op.get_bind().execute("""SELECT setval('question_id_seq', (SELECT max(id) FROM question));""")
3
Source : 1e05a293f402_eeml_registration_form.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='eeml2020').first()
form = session.query(RegistrationForm).filter_by(event_id=event.id).first()
if form:
op.execute("""DELETE FROM registration_question WHERE registration_form_id={}""".format(form.id))
op.execute("""DELETE FROM registration_section WHERE registration_form_id={}""".format(form.id))
op.execute("""DELETE FROM registration_form WHERE id={}""".format(form.id))
session.commit()
3
Source : 35cdc3c51184_add_validation_text.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def upgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
op.add_column('question', sa.Column('validation_text', sa.String(), nullable=True))
update_question_data()
def update_question(session, question_id, validation_text):
3
Source : 35cdc3c51184_add_validation_text.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def update_question_data():
bind = op.get_bind()
session = orm.Session(bind=bind)
update_question(session, 1, 'Enter 50 to 150 words')
update_question(session, 2, 'Enter 50 to 150 words')
update_question(session, 3, 'Enter a maximum of 80 words')
update_question(session, 4, 'Enter a maximum of 80 words')
update_question(session, 5, 'Enter a maximum of 150 words')
update_question(session, 9, 'Enter a maximum of 150 words')
update_question(session, 16, 'Enter a maximum of 150 words')
update_question(session, 18, 'Enter a maximum of 150 words')
def downgrade():
3
Source : 4605cce59919_add_ai4d.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='ai4d2020').first()
app_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
session.query(Question).filter_by(application_form_id=app_form.id).delete()
session.query(Section).filter_by(application_form_id=app_form.id).delete()
session.query(ApplicationForm).filter_by(event_id=event.id).delete()
session.query(Event).filter_by(key='ai4d2020').delete()
session.commit()
3
Source : 4d8b254d7e7e_link_user_to_organisation.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def upgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
op.add_column('app_user', sa.Column('organisation_id', sa.Integer(), nullable=True))
op.create_foreign_key('fk_user_organisation', 'app_user', 'organisation', ['organisation_id'], ['id'])
op.execute("""UPDATE app_user SET organisation_id = 1""")
op.alter_column('app_user', 'organisation_id', nullable=False)
op.add_column('organisation', sa.Column('system_name', sa.String(length=50), nullable=True))
op.execute("""UPDATE organisation SET system_name = 'Baobab' WHERE id = 1""")
op.execute("""UPDATE organisation SET system_name = 'EEML Portal' WHERE id = 2""")
op.execute("""UPDATE organisation SET system_name = 'Baobab Dev' WHERE id = 3""")
def downgrade():
3
Source : 6d34d1ab6864_eeml_review_form.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='eeml2020').first()
application_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
form = session.query(ReviewForm).filter_by(application_form_id=application_form.id).first()
if form:
session.query(ReviewQuestion).filter_by(review_form_id=form.id).delete()
session.query(ReviewConfiguration).filter_by(review_form_id=form.id).delete()
form = session.query(ReviewForm).filter_by(application_form_id=application_form.id).delete()
session.commit()
session.flush()
op.get_bind().execute("""SELECT setval('review_form_id_seq', (SELECT max(id) FROM review_form));""")
op.get_bind().execute("""SELECT setval('review_question_id_seq', (SELECT max(id) FROM review_question));""")
3
Source : 87213d612eaf_eeml_application_form.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='eeml2020').first()
app_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
session.query(Question).filter_by(application_form_id=app_form.id).delete()
session.query(Section).filter_by(application_form_id=app_form.id).delete()
session.query(ApplicationForm).filter_by(event_id=event.id).delete()
session.query(Event).filter_by(key='eeml2020').delete()
session.commit()
op.get_bind().execute("""SELECT setval('event_id_seq', (SELECT max(id) FROM event));""")
op.get_bind().execute("""SELECT setval('application_form_id_seq', (SELECT max(id) FROM application_form));""")
op.get_bind().execute("""SELECT setval('section_id_seq', (SELECT max(id) FROM section));""")
op.get_bind().execute("""SELECT setval('question_id_seq', (SELECT max(id) FROM question));""")
3
Source : 88cc4397bdf5_ai4d_org.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def upgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
ai4d = Organisation('AI4D Africa', 'Baobab', small_logo='ai4d_square_logo.png', large_logo='ai4d_logo.png',
icon_logo='ai4d_white.png', domain='ai4d', url='http://www.ai4d.ai', email_from='[email protected]',
system_url='https://baobab.ai4d.ai', privacy_policy='AI4D_privacy_policy_en_fr.pdf',
languages=[{"code": "en", "description": "English"}, {"code": "fr", "description": "French"}])
session.add(ai4d)
session.commit()
def downgrade():
3
Source : 88cc4397bdf5_ai4d_org.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
session.query(Organisation).filter_by(name='AI4D Africa').delete()
session.commit()
3
Source : 964ead196cb9_add_miniconf_url.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def upgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
op.add_column('event', sa.Column('miniconf_url', sa.String(length=100), nullable=True))
event = session.query(Event).filter_by(key='eeml2020').first()
op.execute("""UPDATE event SET miniconf_url = 'miniconf.eeml.eu' WHERE id = {}""".format(event.id))
def downgrade():
3
Source : b4c1dfa70233_add_ethnicity_question.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
# Delete the new question
# question = session.query(Question).filter(Question.headline == 'You Ethnicity (South African applicants only)').delete()
# Undo changes to additional comments question
question = session.query(Question).filter(Question.headline == 'Any additional comments or remarks for the selection committee?').first()
question.validation_regex = None
question.validation_text = None
question.description = None
# Undo changes to anything relevant question
question = session.query(Question).filter(Question.headline == 'Anything else you think relevant, for example links to personal webpage, papers, GitHub/code repositories, community and outreach activities. ').first()
question.validation_text = None
session.commit()
3
Source : c3c5ef958ca1_.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
# pass
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='kambulemasters2020').first()
app_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
nominator = session.query(Section).filter(Section.application_form_id == app_form.id, Section.order == 2).first()
nominator.depends_on_question_id = None
session.query(Question).filter_by(application_form_id=app_form.id).delete()
session.query(Section).filter_by(application_form_id=app_form.id).delete()
session.query(ApplicationForm).filter_by(event_id=event.id).delete()
session.query(Event).filter_by(key='kambulemasters2020').delete()
session.commit()
3
Source : de12a6f382c1_ai4d_review_form.py
with Apache License 2.0
from deep-learning-indaba
with Apache License 2.0
from deep-learning-indaba
def downgrade():
Base.metadata.bind = op.get_bind()
session = orm.Session(bind=Base.metadata.bind)
event = session.query(Event).filter_by(key='ai4d2020').first()
application_form = session.query(ApplicationForm).filter_by(event_id=event.id).first()
form = session.query(ReviewForm).filter_by(application_form_id=application_form.id).first()
if form:
session.query(ReviewQuestion).filter_by(review_form_id=form.id).delete()
session.query(ReviewConfiguration).filter_by(review_form_id=form.id).delete()
form = session.query(ReviewForm).filter_by(application_form_id=application_form.id).delete()
session.commit()
session.flush()
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_person(mysql_engine, mysql_base):
session = Session(mysql_engine)
Person = mysql_base.classes.person
persons = session.query(Person).all()
for person in persons:
yield person
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_patient_identifier(mysql_engine, mysql_base, person_id):
session = Session(mysql_engine)
Patient_identifier = mysql_base.classes.patient_identifier
patient_identifiers = session.query(Patient_identifier).filter(Patient_identifier.patient_id == person_id)
for patient_identifier in patient_identifiers:
yield patient_identifier
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_provider(mysql_engine, mysql_base):
session = Session(mysql_engine)
Provider = mysql_base.classes.provider
providers = session.query(Provider).distinct()
for provider in providers:
yield provider
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_observation_person_id(mysql_engine, mysql_base):
session = Session(mysql_engine)
Observation = mysql_base.classes.obs
observations = session.query(Observation).distinct(Observation.person_id)
for observation in observations:
yield observation
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_observation(mysql_engine, mysql_base):
session = Session(mysql_engine)
Observation = mysql_base.classes.obs
observations = session.query(Observation)
for observation in observations:
yield observation
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_encounter(mysql_engine, mysql_base):
session = Session(mysql_engine)
Encounter = mysql_base.classes.encounter
encounters = session.query(Encounter)
for encounter in encounters:
yield encounter
# line 210
@use('mysql_engine', 'mysql_base')
3
Source : openmrs.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def extract_concept(mysql_engine, mysql_base, concept_id):
session = Session(mysql_engine)
Concept = mysql_base.classes.concept
concepts = session.query(Concept).filter(Concept.concept_id == concept_id)
for concept in concepts:
yield concept
3
Source : cdm5.py
with GNU General Public License v3.0
from dermatologist
with GNU General Public License v3.0
from dermatologist
def load(pgsql_engine, *args):
session = Session(pgsql_engine)
# Person = mysql_base.classes.person
for arg in args:
# className = arg.__class__.__name__
# classDef = mysql_base.classes[className]
arg = session.merge(arg)
session.commit()
3
Source : conftest.py
with MIT License
from Ermlab
with MIT License
from Ermlab
def db_session():
config = ApiConfig()
engine = create_engine(config.DATABASE_URL, echo=config.DEBUG)
with engine.begin() as connection:
Base.metadata.drop_all(connection)
Base.metadata.create_all(connection)
with Session(engine) as session:
yield session
3
Source : request_context.py
with MIT License
from Ermlab
with MIT License
from Ermlab
def begin_request(self, current_user=None):
self._current_user.set(current_user)
self._correlation_id.set(uuid.uuid4())
session = Session(self._engine)
session.begin()
self._db_session.set(session)
def end_request(self, commit=True):
3
Source : bulk_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_flush_no_pk(n):
"""Individual INSERT statements via the ORM, calling upon last row id"""
session = Session(bind=engine)
for chunk in range(0, n, 1000):
session.add_all(
[
Customer(
name="customer name %d" % i,
description="customer description %d" % i,
)
for i in range(chunk, chunk + 1000)
]
)
session.flush()
session.commit()
@Profiler.profile
3
Source : bulk_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bulk_save_return_pks(n):
"""Individual INSERT statements in "bulk", but calling upon last row id"""
session = Session(bind=engine)
session.bulk_save_objects(
[
Customer(
name="customer name %d" % i,
description="customer description %d" % i,
)
for i in range(n)
],
return_defaults=True,
)
session.commit()
@Profiler.profile
3
Source : bulk_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_flush_pk_given(n):
"""Batched INSERT statements via the ORM, PKs already defined"""
session = Session(bind=engine)
for chunk in range(0, n, 1000):
session.add_all(
[
Customer(
id=i + 1,
name="customer name %d" % i,
description="customer description %d" % i,
)
for i in range(chunk, chunk + 1000)
]
)
session.flush()
session.commit()
@Profiler.profile
3
Source : bulk_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bulk_save(n):
"""Batched INSERT statements via the ORM in "bulk", discarding PKs."""
session = Session(bind=engine)
session.bulk_save_objects(
[
Customer(
name="customer name %d" % i,
description="customer description %d" % i,
)
for i in range(n)
]
)
session.commit()
@Profiler.profile
3
Source : bulk_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bulk_insert_mappings(n):
"""Batched INSERT statements via the ORM "bulk", using dictionaries."""
session = Session(bind=engine)
session.bulk_insert_mappings(
Customer,
[
dict(
name="customer name %d" % i,
description="customer description %d" % i,
)
for i in range(n)
],
)
session.commit()
@Profiler.profile
3
Source : bulk_updates.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_flush(n):
"""UPDATE statements via the ORM flush process."""
session = Session(bind=engine)
for chunk in range(0, n, 1000):
customers = (
session.query(Customer)
.filter(Customer.id.between(chunk, chunk + 1000))
.all()
)
for customer in customers:
customer.description += "updated"
session.flush()
session.commit()
3
Source : large_resultsets.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_full_objects_list(n):
"""Load fully tracked ORM objects into one big list()."""
sess = Session(engine)
list(sess.query(Customer).limit(n))
@Profiler.profile
3
Source : large_resultsets.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_full_objects_chunks(n):
"""Load fully tracked ORM objects a chunk at a time using yield_per()."""
sess = Session(engine)
for obj in sess.query(Customer).yield_per(1000).limit(n):
pass
@Profiler.profile
3
Source : large_resultsets.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_bundles(n):
"""Load lightweight "bundle" objects using the ORM."""
sess = Session(engine)
bundle = Bundle(
"customer", Customer.id, Customer.name, Customer.description
)
for row in sess.query(bundle).yield_per(10000).limit(n):
pass
@Profiler.profile
3
Source : large_resultsets.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_columns(n):
"""Load individual columns into named tuples using the ORM."""
sess = Session(engine)
for row in (
sess.query(Customer.id, Customer.name, Customer.description)
.yield_per(10000)
.limit(n)
):
pass
@Profiler.profile
3
Source : short_selects.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_query(n):
"""test a straight ORM query of the full entity."""
session = Session(bind=engine)
for id_ in random.sample(ids, n):
session.query(Customer).filter(Customer.id == id_).one()
@Profiler.profile
3
Source : short_selects.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_query_cols_only(n):
"""test an ORM query of only the entity columns."""
session = Session(bind=engine)
for id_ in random.sample(ids, n):
session.query(Customer.id, Customer.name, Customer.description).filter(
Customer.id == id_
).one()
@Profiler.profile
3
Source : short_selects.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_baked_query(n):
"""test a baked query of the full entity."""
bakery = baked.bakery()
s = Session(bind=engine)
for id_ in random.sample(ids, n):
q = bakery(lambda s: s.query(Customer))
q += lambda q: q.filter(Customer.id == bindparam("id"))
q(s).params(id=id_).one()
@Profiler.profile
3
Source : short_selects.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_baked_query_cols_only(n):
"""test a baked query of only the entity columns."""
bakery = baked.bakery()
s = Session(bind=engine)
for id_ in random.sample(ids, n):
q = bakery(
lambda s: s.query(Customer.id, Customer.name, Customer.description)
)
q += lambda q: q.filter(Customer.id == bindparam("id"))
q(s).params(id=id_).one()
@Profiler.profile
3
Source : single_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_orm_commit(n):
"""Individual INSERT/COMMIT pairs via the ORM"""
for i in range(n):
session = Session(bind=engine)
session.add(
Customer(
name="customer name %d" % i,
description="customer description %d" % i,
)
)
session.commit()
@Profiler.profile
3
Source : single_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bulk_save(n):
"""Individual INSERT/COMMIT pairs using the "bulk" API """
for i in range(n):
session = Session(bind=engine)
session.bulk_save_objects(
[
Customer(
name="customer name %d" % i,
description="customer description %d" % i,
)
]
)
session.commit()
@Profiler.profile
3
Source : single_inserts.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bulk_insert_dictionaries(n):
"""Individual INSERT/COMMIT pairs using the "bulk" API with dictionaries"""
for i in range(n):
session = Session(bind=engine)
session.bulk_insert_mappings(
Customer,
[
dict(
name="customer name %d" % i,
description="customer description %d" % i,
)
],
)
session.commit()
@Profiler.profile
3
Source : space_invaders.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def main():
"""Initialize the database and establish the game loop."""
e = create_engine("sqlite://")
Base.metadata.create_all(e)
session = Session(e)
init_glyph(session)
session.commit()
window = setup_curses()
state = {}
start(session, window, state)
while True:
update_state(session, window, state)
draw(session, window, state)
time.sleep(0.01)
if __name__ == "__main__":
3
Source : test_versioning.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def setUp(self):
self.session = Session(engine)
self.Base = declarative_base()
versioned_session(self.session)
def tearDown(self):
See More Examples