Skip to content

Commit 5260716

Browse files
committed
Data type inference
1 parent 4327ecd commit 5260716

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

sqlalchemy_datastore/_types.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"TIMESTAMP": sqlalchemy.types.TIMESTAMP,
4242
"TIME": sqlalchemy.types.TIME,
4343
"GEOGRAPHY": sqlalchemy.types.ARRAY,
44-
"NONE": sqlalchemy.types.NullType,
44+
"NULL": sqlalchemy.types.NullType,
4545
"KEY": sqlalchemy.types.JSON
4646
}
4747

@@ -65,9 +65,22 @@
6565
GEOPOINT = _type_map["GEOGRAPHY"]
6666
STRUCT_FIELD_TYPES = _type_map["STRUCT"]
6767
RECORD_FIELD_TYPES = _type_map["RECORD"]
68-
NONE_TYPES = _type_map["NONE"]
68+
NULL_TYPE = _type_map["NULL"]
6969
KEY_TYPE = _type_map["KEY"]
7070

71+
_property_type = {
72+
"Date/Time": DATETIME,
73+
"GeoPt": GEOPOINT,
74+
"Integer": INTEGER,
75+
"Key": KEY_TYPE,
76+
"Blob": BYTES,
77+
"Boolean": BOOLEAN,
78+
"EmbeddedEntity": STRUCT_FIELD_TYPES,
79+
"Float": FLOAT,
80+
"NULL": NULL_TYPE,
81+
"String": STRING
82+
}
83+
7184

7285
def _get_transitive_schema_fields(fields):
7386
"""

sqlalchemy_datastore/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1717
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1818
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19-
import os
2019
import logging
2120
from typing import Any, List, Optional, Dict
2221
from concurrent import futures
@@ -32,7 +31,7 @@
3231
from sqlalchemy.sql.expression import TextClause
3332

3433
from google.cloud import firestore_admin_v1
35-
from google.cloud.firestore_admin_v1.types import ListDatabasesResponse, Database
34+
from google.cloud.firestore_admin_v1.types import Database
3635
from google.oauth2 import service_account
3736

3837
logger = logging.getLogger('sqlalchemy.dialects.CloudDatastore')
@@ -483,14 +482,14 @@ def get_columns(self, connection: Connection, table_name: str, schema: str | Non
483482
credentials_base64=self.credentials_base64,
484483
database=schema
485484
)
486-
ancestor_key = client.key("__kind__", table_name)
487-
query = client.query(kind="__property__", ancestor=ancestor_key)
485+
query = client.query(kind="__Stat_PropertyType_PropertyName_Kind__")
486+
query.add_filter("kind_name", "=", table_name)
488487
properties = list(query.fetch())
489488

490489
def process_property(property):
491490
return {
492-
"name": property.key.name,
493-
"type": _types.STRING, # TODO:Change to other type
491+
"name": property["property_name"],
492+
"type": _types._property_type[property["property_type"]],
494493
"nullable": True,
495494
"comment": "",
496495
"default": None,

0 commit comments

Comments
 (0)