summaryrefslogtreecommitdiff
path: root/examples/performance/bulk_inserts.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /examples/performance/bulk_inserts.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'examples/performance/bulk_inserts.py')
-rw-r--r--examples/performance/bulk_inserts.py115
1 files changed, 65 insertions, 50 deletions
diff --git a/examples/performance/bulk_inserts.py b/examples/performance/bulk_inserts.py
index 9c3cff5b2..52f0f32e6 100644
--- a/examples/performance/bulk_inserts.py
+++ b/examples/performance/bulk_inserts.py
@@ -36,12 +36,15 @@ 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.add_all(
+ [
+ Customer(
+ name="customer name %d" % i,
+ description="customer description %d" % i,
+ )
+ for i in range(chunk, chunk + 1000)
+ ]
+ )
session.flush()
session.commit()
@@ -50,13 +53,16 @@ def test_flush_no_pk(n):
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.bulk_save_objects(
+ [
+ Customer(
+ name="customer name %d" % i,
+ description="customer description %d" % i,
+ )
+ for i in range(n)
+ ],
+ return_defaults=True,
+ )
session.commit()
@@ -65,13 +71,16 @@ 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.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()
@@ -80,13 +89,15 @@ def test_flush_pk_given(n):
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.bulk_save_objects(
+ [
+ Customer(
+ name="customer name %d" % i,
+ description="customer description %d" % i,
+ )
+ for i in range(n)
+ ]
+ )
session.commit()
@@ -94,13 +105,16 @@ def test_bulk_save(n):
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.bulk_insert_mappings(
+ Customer,
+ [
+ dict(
+ name="customer name %d" % i,
+ description="customer description %d" % i,
+ )
+ for i in range(n)
+ ],
+ )
session.commit()
@@ -112,11 +126,12 @@ def test_core_insert(n):
Customer.__table__.insert(),
[
dict(
- name='customer name %d' % i,
- description='customer description %d' % i
+ name="customer name %d" % i,
+ description="customer description %d" % i,
)
for i in range(n)
- ])
+ ],
+ )
@Profiler.profile
@@ -125,30 +140,30 @@ def test_dbapi_raw(n):
conn = engine.pool._creator()
cursor = conn.cursor()
- compiled = Customer.__table__.insert().values(
- name=bindparam('name'),
- description=bindparam('description')).\
- compile(dialect=engine.dialect)
+ compiled = (
+ Customer.__table__.insert()
+ .values(name=bindparam("name"), description=bindparam("description"))
+ .compile(dialect=engine.dialect)
+ )
if compiled.positional:
args = (
- ('customer name %d' % i, 'customer description %d' % i)
- for i in range(n))
+ ("customer name %d" % i, "customer description %d" % i)
+ for i in range(n)
+ )
else:
args = (
dict(
- name='customer name %d' % i,
- description='customer description %d' % i
+ name="customer name %d" % i,
+ description="customer description %d" % i,
)
for i in range(n)
)
- cursor.executemany(
- str(compiled),
- list(args)
- )
+ cursor.executemany(str(compiled), list(args))
conn.commit()
conn.close()
-if __name__ == '__main__':
+
+if __name__ == "__main__":
Profiler.main()