ws.db.execution module

class ws.db.execution.DeferrableExecutionQueue(conn, chunk_size)

Bases: object

An execution wrapper which defers the execution of statements until the queue is full.

This is useful to aggregate the values from Python generators to utilize the executemany execution strategy.

Note

If multiple different statements are being deferred, their queues are executed in the same order they were added, so statements from the second queue can depend on the statements from the first queue and so on. As soon as the size of any queue reaches the size limit, all queues are executed - otherwise the queues may get out of sync and execution may hit constraint errors.

Parameters
  • conn (sqlalchemy.engine.Connection) – a connection (with an established transaction) to the database where the statements are executed

  • chunk_size (int) – maximum queue size

execute(statement, *multiparams, **params)

Adds a statement into the execution queue.

The semantics of the parameters is the same as of sqlalchemy.engine.Connection.execute().

execute_deferred()

Execute all deferred statements and clear the queue.