zut.db.DbAdapter
- class zut.db.DbAdapter(origin: T_Connection | str | dict | ParseResult, *, password_required: bool = False, autocommit: bool = None, tz: tzinfo | str | None = None, table: str | None = None, schema: str | None = None)
Bases:
Generic
[T_Connection
,T_Cursor
]Base class for database adapters.
- __init__(origin: T_Connection | str | dict | ParseResult, *, password_required: bool = False, autocommit: bool = None, tz: tzinfo | str | None = None, table: str | None = None, schema: str | None = None)
Create a new adapter. - origin: an existing connection object, or the URL or django alias (e.g. ‘default’) for the new connection to create by the adapter. - autocommit: commit transactions automatically (applies only for connections created by the adapter). - tz: naive datetimes in results are made aware in the given timezone.
Methods
__init__
(origin, *[, password_required, ...])Create a new adapter.
add_table_columns
(table, columns, *[, null, ...])Add column(s) to a table.
close
()convert_value
(value)Convert a value to types supported by the underlying connection adapter.
create_connection
(*, autocommit, **kwargs)create_schema
([schema, if_not_exists, cursor])create_table
(table, columns, *[, ...])Create a table from a list of columns.
cursor
(*[, autoclose])A new cursor object that support the context manager protocol
drop_schema
([schema, if_exists, cursor])drop_table
([table, if_exists, cursor])dumper
([table, add_autoincrement_pk, ...])duplicate_table_structure
([src_table, ...])erase_table
([table, if_exists, cursor])escape_identifier
(value)escape_literal
(value)execute_file
(path[, params, cursor, ...])execute_function
(name[, params, cursor, ...])execute_procedure
(name[, params, cursor, ...])execute_query
(query[, params, cursor, ...])get_columns
([table_or_cursor, cursor])get_db_name
()get_dict
(query[, params, limit, offset, cursor])get_dicts
(query[, params, limit, offset, cursor])get_headers
([table_or_cursor, cursor])get_last_migration_name
(*[, cursor])get_paginated_dicts
(query[, params, offset, ...])get_paginated_select_queries
(query, *, ...)get_scalar
(query[, params, limit, offset, ...])get_scalars
(query[, params, limit, offset, ...])get_tuple
(query[, params, limit, offset, cursor])get_url
(*[, hide_password])is_available
()iter_dicts
(query[, params, limit, offset, ...])migrate
(dir, *[, cursor])schema_exists
([schema, cursor])split_name
([name])table_exists
([table, cursor])to_positional_params
(query, params)truncate_table
([table, if_exists, cascade, ...])Attributes
autocommit
can_add_several_columns
can_cascade_truncate
connection
datetime_aware_sql_type
datetime_naive_sql_type
default_autocommit
default_schema
float_sql_type
function_requires_schema
identifier_quotechar
identity_definition_sql
int_sql_type
is_port_opened
only_positional_params
procedure_caller
procedure_params_parenthesis
split_multi_statement_files
sql_named_placeholder
sql_placeholder
str_key_sql_type
str_sql_type
table_in_path
temporary_prefix
truncate_with_delete
Use Django's HTTP 404 exception instead of NotFoundError (if Django is available).
scheme
default_port
A specific table associated to this adapter.
A specific schema associated to this adapter.
- add_table_columns(table: str | tuple, columns: list[str | Header], *, null=False, cursor: T_Cursor = None)
Add column(s) to a table.
NOTE: This method does not intend to manage all cases, but only those usefull for zut library internals.
- convert_value(value: Any)
Convert a value to types supported by the underlying connection adapter.
- create_table(table: str | tuple, columns: list[str | Header], *, unique_together: list[tuple[str | Header]] = [], if_not_exists=False, cursor: T_Cursor = None)
Create a table from a list of columns.
NOTE: This method does not intend to manage all cases, but only those usefull for zut library internals.
- cursor(*, autoclose=True, **kwargs) T_Cursor
A new cursor object that support the context manager protocol
- schema: str
A specific schema associated to this adapter. Used for example as default table for dumper.
- table: str
A specific table associated to this adapter. Used for example as default table for dumper.
- use_http404 = False
Use Django’s HTTP 404 exception instead of NotFoundError (if Django is available).