Skip to content

Commit daf6c08

Browse files
committed
django: add DatabaseIntrospection.get_table_description() stub
refs #248
1 parent a54dd02 commit daf6c08

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

packages/django-google-spanner/spanner/django/introspection.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,44 @@
55
# https://developers.google.com/open-source/licenses/bsd
66

77
from django.db.backends.base.introspection import (
8-
BaseDatabaseIntrospection, TableInfo,
8+
BaseDatabaseIntrospection, FieldInfo, TableInfo,
99
)
10+
from google.cloud.spanner_v1.proto import type_pb2
1011

1112

1213
class DatabaseIntrospection(BaseDatabaseIntrospection):
14+
data_types_reverse = {
15+
type_pb2.BOOL: 'BooleanField',
16+
type_pb2.BYTES: 'BinaryField',
17+
type_pb2.DATE: 'DateField',
18+
type_pb2.FLOAT64: 'FloatField',
19+
type_pb2.INT64: 'IntegerField',
20+
type_pb2.STRING: 'TextField',
21+
type_pb2.TIMESTAMP: 'DateTimeField',
22+
}
23+
1324
def get_table_list(self, cursor):
1425
"""Return a list of table and view names in the current database."""
1526
# The second TableInfo field is 't' for table or 'v' for view.
1627
return [TableInfo(row[0], 't') for row in cursor.list_tables()]
28+
29+
def get_table_description(self, cursor, table_name):
30+
"""
31+
Return a description of the table with the DB-API cursor.description
32+
interface.
33+
"""
34+
cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
35+
return [
36+
FieldInfo(
37+
line.name,
38+
line.type_code,
39+
# TODO: Fill these in as they're implemented.
40+
None, # display_size
41+
None, # internal_size
42+
None, # precision
43+
None, # scale
44+
None, # null_ok
45+
None, # default
46+
)
47+
for line in cursor.description
48+
]

0 commit comments

Comments
 (0)