diff --git a/pyproject.toml b/pyproject.toml index ea89ebc..e509319 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "queryme" -version = "0.2.1" +version = "0.2.2" description = "Shared query toolkit for the Zablab platform — descriptor schema, validator, compiler. Consumed by every DB-bearing microservice." requires-python = ">=3.11" dependencies = [ diff --git a/src/queryme/__init__.py b/src/queryme/__init__.py index 050f2d2..a2ace72 100644 --- a/src/queryme/__init__.py +++ b/src/queryme/__init__.py @@ -52,4 +52,4 @@ "validate_against_schema", ] -__version__ = "0.2.1" +__version__ = "0.2.2" diff --git a/src/queryme/compiler.py b/src/queryme/compiler.py index 892b9c5..d9044fd 100644 --- a/src/queryme/compiler.py +++ b/src/queryme/compiler.py @@ -12,6 +12,7 @@ from __future__ import annotations +from collections.abc import Callable from typing import Any, cast from sqlalchemy import ( @@ -68,14 +69,23 @@ def __init__(self, issues: list[ValidationIssue]) -> None: # Type mapping (closed set per schema.ColumnType) # --------------------------------------------------------------------------- - -_TYPE_MAP: dict[ColumnType, type[TypeEngine[Any]]] = { +# Factories rather than raw classes so we can pass constructor flags +# where needed. ``Uuid(as_uuid=False)`` makes the synthetic column +# accept and emit string UUIDs, which is what JSON callers send and +# what HTTP responses serialise to anyway — saves every service from +# coercing both sides. Result rows for the underlying real PG column +# (declared as ``Uuid(as_uuid=True)`` in the service's models) flow +# through the same way because the synthetic column type only +# influences bind/result processing on the synthetic ``Table``, not +# the actual DB-side column. +_TypeFactory = Callable[[], TypeEngine[Any]] +_TYPE_FACTORIES: dict[ColumnType, _TypeFactory] = { "string": String, "text": Text, "integer": Integer, "float": Float, "boolean": Boolean, - "uuid": Uuid, + "uuid": lambda: Uuid(as_uuid=False), "datetime": DateTime, "date": Date, "json": JSON, @@ -181,7 +191,7 @@ def _build_table(metadata: MetaData, table_def: TableDef) -> Table: because joins are explicit in the descriptor.""" cols: list[Column[Any]] = [] for c in table_def.columns: - sa_type = _TYPE_MAP[c.type]() + sa_type = _TYPE_FACTORIES[c.type]() cols.append( Column(c.name, sa_type, nullable=c.nullable, primary_key=c.primary) ) diff --git a/uv.lock b/uv.lock index 72ba7cd..81d988b 100644 --- a/uv.lock +++ b/uv.lock @@ -982,7 +982,7 @@ wheels = [ [[package]] name = "queryme" -version = "0.2.1" +version = "0.2.2" source = { editable = "." } dependencies = [ { name = "pydantic" },