The DBAPI's API inserting rows in bulk.
(n)
| 134 | |
| 135 | @Profiler.profile |
| 136 | def test_dbapi_raw(n): |
| 137 | """The DBAPI's API inserting rows in bulk.""" |
| 138 | |
| 139 | conn = engine.pool._creator() |
| 140 | cursor = conn.cursor() |
| 141 | compiled = ( |
| 142 | Customer.__table__.insert() |
| 143 | .values(name=bindparam("name"), description=bindparam("description")) |
| 144 | .compile(dialect=engine.dialect) |
| 145 | ) |
| 146 | |
| 147 | if compiled.positional: |
| 148 | args = ( |
| 149 | ("customer name %d" % i, "customer description %d" % i) |
| 150 | for i in range(n) |
| 151 | ) |
| 152 | else: |
| 153 | args = ( |
| 154 | dict( |
| 155 | name="customer name %d" % i, |
| 156 | description="customer description %d" % i, |
| 157 | ) |
| 158 | for i in range(n) |
| 159 | ) |
| 160 | |
| 161 | cursor.executemany(str(compiled), list(args)) |
| 162 | conn.commit() |
| 163 | conn.close() |
| 164 | |
| 165 | |
| 166 | if __name__ == "__main__": |