Skip to content

Commit 4dec594

Browse files
committed
convert postgresql type to json schema type for queryables
1 parent ca2e94f commit 4dec594

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tifeatures/dbmodel.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ class Column(BaseModel):
1313
type: str
1414
description: Optional[str]
1515

16+
@property
17+
def json_type(self):
18+
"""Return JSON field type."""
19+
type = self.type
20+
if any(
21+
[
22+
type.startswith("int"),
23+
type.startswith("num"),
24+
type.startswith("float"),
25+
]
26+
):
27+
return "number"
28+
if type.startswith("bool"):
29+
return "boolean"
30+
if type.endswith("[]"):
31+
return "array"
32+
if any([type.startswith("json"), type.startswith("geo")]):
33+
return "object"
34+
return "string"
35+
1636

1737
class GeometryColumn(BaseModel):
1838
"""Model for PostGIS geometry/geography column."""

tifeatures/layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def queryables(self) -> Dict:
438438
for col in geometries
439439
}
440440
props = {
441-
col.name: {"name": col.name, "type": col.type}
441+
col.name: {"name": col.name, "type": col.json_type}
442442
for col in self.properties
443443
if col.name not in geoms
444444
}

0 commit comments

Comments
 (0)