Base API

class django_spanner.base.DatabaseWrapper(settings_dict, alias='default')[source]
Database = <module 'google.cloud.spanner_dbapi' from '/workspace/.nox/docs/lib/python3.8/site-packages/google/cloud/spanner_dbapi/__init__.py'>
SchemaEditorClass

alias of django_spanner.schema.DatabaseSchemaEditor

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

alias of django_spanner.creation.DatabaseCreation

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

dict

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.

init_connection_state()[source]

Initialize the state of the existing connection.

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

alias of django_spanner.introspection.DatabaseIntrospection

is_usable()[source]

Check whether the connection is valid.

Return type

bool

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

alias of django_spanner.operations.DatabaseOperations

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 explcit 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

Time zone for datetimes stored as naive values in the database.

Return a tzinfo object or None.

This is only needed when time zone support is enabled and the database doesn’t support time zones. (When the database supports time zones, the adapter handles aware datetimes so Django doesn’t need to.)

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.