Introspection API

class django_spanner.introspection.DatabaseIntrospection(connection)[source]

A Spanner-specific version of Django introspection utilities.

django_table_names(only_existing=False, include_views=True)

Return a list of all table names that have associated Django models and are in INSTALLED_APPS.

If only_existing is True, include only the tables in the database.

get_constraints(cursor, table_name)[source]

Retrieve the Spanner Table column constraints.

Parameters
  • cursor (Cursor) – The cursor in the linked database.

  • table_name (str) – The name of the table.

Return type

dict

Returns

A dictionary with constraints.

get_field_type(data_type, description)[source]

A hook for a Spanner database to use the cursor description to match a Django field type to the database column.

Parameters
  • data_type (int) – One of Spanner’s standard data types.

  • description (ColumnInfo) – A description of Spanner column data type.

Return type

str

Returns

The corresponding type of Django field.

get_key_columns(cursor, table_name)[source]

Return a list of (column_name, referenced_table, referenced_column) for all key columns in the given table.

get_primary_key_column(cursor, table_name)[source]

Return Primary Key column.

Parameters
  • cursor (Cursor) – A reference to a Spanner Database cursor.

  • table_name (str) – The name of the table.

Return type

str

Returns

The name of the PK column.

get_relations(cursor, table_name)[source]

Return a dictionary of {field_name: (field_name_other_table, other_table)} representing all the relationships in the table.

Parameters
  • cursor (Cursor) – A reference to a Spanner Database cursor.

  • table_name (str) – The name of the Cloud Spanner Database.

Return type

dict

Returns

A dictionary representing column relationships to other tables.

get_sequences(cursor, table_name, table_fields=())

Return a list of introspected sequences for table_name. Each sequence is a dict: {‘table’: <table_name>, ‘column’: <column_name>}. An optional ‘name’ key can be added if the backend supports named sequences.

get_table_description(cursor, table_name)[source]

Return a description of the table with the DB-API cursor.description interface.

Parameters
  • cursor (Cursor) – A reference to a Spanner Database cursor.

  • table_name (str) – The name of the table.

Return type

list

Returns

A description of the table with the DB-API cursor.description interface.

get_table_list(cursor)[source]

Return a list of table and view names in the current database.

Parameters

cursor (Cursor) – A reference to a Spanner Database cursor.

Return type

list

Returns

A list of table and view names in the current database.

identifier_converter(name)

Apply a conversion to the identifier for the purposes of comparison.

The default identifier converter is for case sensitive comparison.

installed_models(tables)

Return a set of all models represented by the provided list of table names.

sequence_list()

Return a list of information about all DB sequences for all models in all apps.

table_names(cursor=None, include_views=False)

Return a list of names of all tables that exist in the database. Sort the returned table list by Python’s default sorting. Do NOT use the database’s ORDER BY here to avoid subtle differences in sorting order between databases.