swh.core.db package#
Submodules#
- swh.core.db.common module
- swh.core.db.db_utils module- now()
- stored_procedure()
- jsonize()
- connect_to_conninfo()
- swh_db_version()
- swh_db_versions()
- swh_db_upgrade()
- swh_db_module()
- swh_set_db_module()
- swh_set_db_version()
- swh_db_flavor()
- import_swhmodule()
- get_sql_for_package()
- populate_database_for_package()
- initialize_database_for_module()
- get_database_info()
- parse_dsn_or_dbname()
- init_admin_extensions()
- create_database_for_package()
- dsn_with_password()
- execute_sqlfiles()
 
Module contents#
- swh.core.db.value_as_pg_text(data: Any) str[source]#
- Render the given data in the postgresql text format. - NULL values are handled outside of this function (either by - render_array_element(), or by- BaseDb.copy_to().)
- swh.core.db.escape_copy_column(column: str) str[source]#
- Escape the text representation of a column for use by COPY. 
- class swh.core.db.BaseDb(conn: Connection[Any], pool: ConnectionPool | None = None)[source]#
- Bases: - object- Base class for swh.*.*Db. - cf. swh.storage.db.Db, swh.archiver.db.ArchiverDb - create a DB proxy - Parameters:
- conn – psycopg connection to the SWH DB 
- pool – psycopg pool of connections 
 
 - classmethod connect(*args, **kwargs) BaseDbType[source]#
- factory method to create a DB proxy - Accepts all arguments of psycopg.connect; only some specific possibilities are reported below. - Parameters:
- connstring – libpq2 connection string 
 
 - cursor(cur_arg: Cursor | None = None) Cursor[source]#
- get a cursor: from cur_arg if given, or a fresh one otherwise - meant to avoid boilerplate if/then/else in methods that proxy stored procedures 
 - transaction() Iterator[Cursor][source]#
- context manager to execute within a DB transaction - Yields:
- a psycopg cursor 
 
 - copy_to(items: Iterable[Mapping[str, Any]], tblname: str, columns: Iterable[str], cur: Cursor | None = None, item_cb: Callable[[Any], Any] | None = None, default_values: Mapping[str, Any] | None = None) None[source]#
- Run the COPY command to insert the columns of each element of items into tblname. - Parameters:
- items – dictionaries of data to copy into tblname. 
- tblname – name of the destination table. 
- columns – columns of the destination table. Elements of items must have these set as keys. 
- default_values – dictionary of default values to use when inserting entries in tblname. 
- cur – a db cursor; if not given, a new cursor will be created. 
- item_cb – optional callback, run on each element of items, when it is copied.