|
5 | 5 | # https://developers.google.com/open-source/licenses/bsd |
6 | 6 |
|
7 | 7 | from django.db.backends.base.introspection import ( |
8 | | - BaseDatabaseIntrospection, TableInfo, |
| 8 | + BaseDatabaseIntrospection, FieldInfo, TableInfo, |
9 | 9 | ) |
| 10 | +from google.cloud.spanner_v1.proto import type_pb2 |
10 | 11 |
|
11 | 12 |
|
12 | 13 | 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 | + |
13 | 24 | def get_table_list(self, cursor): |
14 | 25 | """Return a list of table and view names in the current database.""" |
15 | 26 | # The second TableInfo field is 't' for table or 'v' for view. |
16 | 27 | 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