co3.managers.sql module¶
Common on insert behavior
Tables with unique constraints have been equipped with
sqlite_on_conflict_unique
flags, enabling conflicting bulk inserts to replace conflicting rows gracefully. No need to worry about explicitly handling upserts.The bulk insert via conn.execute(<insert>,<row_list>) automatically ignores irrelevant column names within provided record dicts, whereas explicit .values() calls for non-bulk inserts will throw errors if not aligned perfectly. We want to keep these bulk calls AND allow update/replacements on conflict; the setting above allows this bulk usage to continue as is.
- class co3.managers.sql.SQLManager(*args, **kwargs)[source]¶
Bases:
RelationalManager
[SQLTable
]Core schema table manager. Exposes common operations and facilitates joint operations needed for highly connected schemas.
In particular, Managers expose insertion abstractions that take table-indexed groups of rows and bundle them under a single transaction. This is important for table groups with foreign keys and cascading deletions: inserts need to be coordinated. Note that actually collecting the inserts that need to take place is outside the scope of the Manager (see the Collector). We do, however, implement a
sync
operation that can saturates a router with events (dynamically) and sweeps up inserts on session basis from an attached collector.- __init__(*args, **kwargs)[source]¶
The insert lock is a reentrant lock, meaning the same thread can acquire the lock again without deadlocking (simplifying across methods of this class that need it).
- insert_many(connection, inserts)[source]¶
Perform provided table inserts, aligning the insert format of
Collector.collect_inserts()
.- Parameters:
inserts (
dict
) – component-indexed dictionary of insert lists
- recreate(schema, engine)[source]¶
Ideally this remains open, as we can’t necessarily rely on a SQLAlchemy metadata object for all kinds of SQLDatabases (would depend on the backend, for instance).
Haven’t quite nailed down how backend instances should be determined; something like SQLAlchemySQLManager doesn’t seem great. Nevertheless, this method likely cannot be generalized at the “SQL” (general) level.
- Return type:
None