relstorage.adapters.batch – Batch table row insert/delete support

Batch table row insert/delete support.

class RowBatcher(cursor, row_limit=None, delete_placeholder=None, insert_placeholder=None, bind_limit=None)[source]

Bases: object

Generic row batcher.

Inserting can use whatever paramater placeholder format and parameter format the cursor supports.

Deleting needs to use ordered parameters. The placeholder can be set in the delete_placeholder attribute.

delete_from(table, **kw)[source]

Returns the number of rows flushed as a result of this operation. That can include inserts.

flush()[source]

Return the tetal number of rows deleted or inserted in this operation. (This is the number requested, in the case of deletes, not the number that actually matched.)

This can be treated as a boolean to discover if anything was flushed.

perf_counter()float

Performance counter for benchmarking.

select_from(columns, table, suffix='', timeout=None, **kw)[source]

Handles a query of the WHERE col IN (?, ?,) type:

``SELECT columns FROM table WHERE col IN (?, ...)``

The keyword arguments should be of length 1, containing an iterable of the values to check: col=(1, 2) or in the dynamic case **{indirect_var: [1, 2]}:

batcher.select_from(('zoid', 'tid',), 'object_state',
                    zoid=oids)

The number of batches needed is determined by the length of the iterator divided by this object’s bind_limit, or, if that’s not set, by the row_limit.

Returns a iterator of matching rows. Matching rows are delivered incrementally, so some number of rows may be delivered and then an exception is raised.

Parameters

timeout (float) – If given, provides a number of seconds that is the approximate maximum amount of time this method will be allowed to take.

Raises

AggregateOperationTimeoutError – If timeout is given, and the cumulative time taken to query and process some subset of batches exceeds timeout. This is checked after each individual batch.

update_set_static(update_set, timeout=None, batch_done_callback=<function RowBatcher.<lambda>>, **kw)[source]

As for select_from(), but the first parameter is the complete static UPDATE statement. It must be uppercase, and startwith “UPDATE”.

Rows are net expected to be returned, so the cursor is completely consumed between batches.

iteritems()

D.items() -> a set-like object providing a view on D’s items