Base API¶
- class django_spanner.base.DatabaseWrapper(settings_dict, alias='default')[source]¶
- Database = <module 'google.cloud.spanner_dbapi' from '/workspace/.nox/docs/lib/python3.9/site-packages/google/cloud/spanner_dbapi/__init__.py'>¶
- SchemaEditorClass¶
- check_constraints(table_names=None)¶
Backends can override this method if they can apply constraint checking (e.g. via “SET CONSTRAINTS ALL IMMEDIATE”). Should raise an IntegrityError if any invalid foreign key references are encountered.
- chunked_cursor()¶
Return a cursor that tries to avoid caching in the database (if supported by the database), otherwise return a regular cursor.
- clean_savepoints()¶
Reset the counter used to generate unique savepoint ids in this thread.
- client_class¶
alias of
django_spanner.client.DatabaseClient
- close()¶
Close the connection to the database.
- close_if_unusable_or_obsolete()¶
Close the current connection if unrecoverable errors have occurred or if it outlived its maximum age.
- commit()¶
Commit a transaction and reset the dirty flag.
- connect()¶
Connect to the database. Assume that the connection is closed.
- constraint_checks_disabled()¶
Disable foreign key constraint checking.
- copy(alias=None)¶
Return a copy of this connection.
For tests that require two connections to the same database.
- create_cursor(name=None)[source]¶
Create a new Database cursor.
- Parameters
name (str) – Currently not used.
- Return type
Cursor
- Returns
The Cursor for this connection.
- creation_class¶
- cursor()¶
Create a cursor, opening a connection if necessary.
- disable_constraint_checking()¶
Backends can implement as needed to temporarily disable foreign key constraint checking. Should return True if the constraints were disabled and will need to be reenabled.
- enable_constraint_checking()¶
Backends can implement as needed to re-enable foreign key constraint checking.
- ensure_connection()¶
Guarantee that a connection to the database is established.
- ensure_timezone()¶
Ensure the connection’s timezone is set to
self.timezone_name
and return whether it changed or not.
- execute_wrapper(wrapper)¶
Return a context manager under which the wrapper is applied to suitable database query executions.
- get_autocommit()¶
Get the autocommit state.
- get_connection_params()[source]¶
Retrieve the connection parameters.
- Return type
- Returns
A dictionary containing the Spanner connection parameters in Django Spanner format.
- get_new_connection(conn_params)[source]¶
Create a new connection with corresponding connection parameters.
- Parameters
conn_params (list) – A List of the connection parameters for
Connection
- Return type
google.cloud.spanner_dbapi.connection.Connection
- Returns
A new Spanner DB API Connection object associated with the given Google Cloud Spanner resource.
- Raises
ValueError
in case the given instance/database doesn’t exist.
- get_rollback()¶
Get the “needs rollback” flag – for advanced use only.
- property instance¶
Reference to a Cloud Spanner Instance containing the Database.
- Return type
Instance
- Returns
A new instance owned by the existing Spanner Client.
- introspection_class¶
- is_usable()[source]¶
Check whether the connection is valid.
- Return type
- Returns
True if the connection is open, otherwise False.
- make_cursor(cursor)¶
Create a cursor without debug logging.
- make_debug_cursor(cursor)¶
Create a cursor that logs all queries in self.queries_log.
- ops_class¶
- prepare_database()¶
Hook to do any database check or preparation, generally called before migrating a project or an app.
- rollback()¶
Roll back a transaction and reset the dirty flag.
- savepoint()¶
Create a savepoint inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit. Do nothing if savepoints are not supported.
- savepoint_commit(sid)¶
Release a savepoint. Do nothing if savepoints are not supported.
- savepoint_rollback(sid)¶
Roll back to a savepoint. Do nothing if savepoints are not supported.
- schema_editor(*args, **kwargs)¶
Return a new instance of this backend’s SchemaEditor.
- set_autocommit(autocommit, force_begin_transaction_with_broken_autocommit=False)¶
Enable or disable autocommit.
The usual way to start a transaction is to turn autocommit off. SQLite does not properly start a transaction when disabling autocommit. To avoid this buggy behavior and to actually enter a new transaction, an explicit BEGIN is required. Using force_begin_transaction_with_broken_autocommit=True will issue an explicit BEGIN with SQLite. This option will be ignored for other backends.
- set_rollback(rollback)¶
Set or unset the “needs rollback” flag – for advanced use only.
- temporary_connection()¶
Context manager that ensures that a connection is established, and if it opened one, closes it to avoid leaving a dangling connection. This is useful for operations outside of the request-response cycle.
Provide a cursor: with self.temporary_connection() as cursor: …
- timezone¶
Return a tzinfo of the database connection time zone.
This is only used when time zone support is enabled. When a datetime is read from the database, it is always returned in this time zone.
When the database backend supports time zones, it doesn’t matter which time zone Django uses, as long as aware datetimes are used everywhere. Other users connecting to the database can choose their own time zone.
When the database backend doesn’t support time zones, the time zone Django uses may be constrained by the requirements of other users of the database.
- timezone_name¶
Name of the time zone of the database connection.
- validate_no_atomic_block()¶
Raise an error if an atomic block is active.
- validate_thread_sharing()¶
Validate that the connection isn’t accessed by another thread than the one which originally created it, unless the connection was explicitly authorized to be shared between threads (via the
inc_thread_sharing()
method). Raise an exception if the validation fails.
- validation_class¶
alias of
django.db.backends.base.validation.BaseDatabaseValidation
- wrap_database_errors¶
Context manager and decorator that re-throws backend-specific database exceptions using Django’s common wrappers.