gpf_vector_to_db.utils.database module¶
- class gpf_vector_to_db.utils.database.DatabaseUtils(db: PgDatabase)¶
Bases :
object
Helpers interface with Postgres.
- __init__(db: PgDatabase)¶
Instanciation.
- Paramètres:
db (PgDatabase) – Postgres database object
- active_schema() str | None ¶
Returns the active schema if present else None
- Renvoie:
active schema name if present
- Type renvoyé:
str | None
- copy_values_data(src_schema_name: str, src_table_name: str, dst_schema_name: str, dst_table_name: str, columns_name: list[str]) Cursor ¶
- Copy data from source to destination table with columns name possibly using
where filter.
- Paramètres:
src_schema_name (str) – source table’s schema
src_table_name (str) – source table’s name
dst_schema_name (str) – destination table’s schema
dst_table_name (str) – destination table’s name
columns_name (list[str]) – columns name to filter on
- create_schema(schema_name: str) Cursor ¶
Creates a schema in the database.
- Paramètres:
schema_name (str) – schema name
- Renvoie:
_description_
- Type renvoyé:
_type_
- drop_schema(schema_name: str, enable_cascade: bool = False) Cursor ¶
Drop a schema, in cascade or not, from the database.
- Paramètres:
schema_name (str) – name of the schema to drop
enable_cascade (bool, optional) – enable DROP in cascade. Defaults to False.
- duplicate_table_structure(src_schema_name: str, src_table_name: str, dst_schema_name: str, dst_table_name: str) Cursor ¶
Create a new table (destination) from the structure of another one (source).
- Paramètres:
src_schema_name (str) – source table’s schema
src_table_name (str) – source table’s name
dst_schema_name (str) – destination table’s schema
dst_table_name (str) – destination table’s name
- execute(sql: str) Cursor ¶
Executes the passed SQL query.
- Paramètres:
sql (str) – SQL query
- execute_file(sql_file: Path, search_path: str | None = None)¶
Executes queries stored in SQL file (.sql). Use carrefully.
- Paramètres:
sql_file (Path) – path to the SQL file to load from
search_path (str | None, optional) – optional schema name to add to the search path, in addition to the public schema. Defaults to None.
- fetch_first_element(sql: str) str | None ¶
Fetches only the firt row of the SQL query.
- Paramètres:
sql (str) – SQL query
- Renvoie:
query first result
- Type renvoyé:
str | None
- is_schema_exists(schema_name: str) bool ¶
Returns True if the given schema exists. Else False.
- Paramètres:
schema_name (str) – name of the schema to check
- Renvoie:
True if the schema exists.
- Type renvoyé:
bool
- is_table_exists(schema_name: str, table_name: str) bool ¶
Returns True if the given table exists. Else False.
- Paramètres:
schema_name (str) – table’s schema name
table_name (str) – table’s name
- Renvoie:
True if the table exists.
- Type renvoyé:
bool
- update_query_to_remove_index(sql: str, schema_name: str, table_name: str) str ¶
Update query to remove indexes of schema_name.table_name at the beginning of the transaction and recreate indexes at the end of the transaction. Only indexes that do not have a dependency constraint are removed
This function is useful for the time of inserting a huge amount of data.
- Paramètres:
sql (str) – query to update
schema_name (str) – table schema
table_name (str) – table name
- Renvoie:
updated query
- Type renvoyé:
str | None