Skip to content

feat(compiler): implement compile_query for v0.2.0 #1

@ClodoCapeo

Description

@ClodoCapeo

Context

queryme.compile_query() is a stub since v0.1.0 (raises NotImplementedError). v0.2.0 implements it so consuming services (ZabTruth first) can ship POST /api/v1/_query.

Reference : ADR 001 §Phase 2 at D:/Document/ZabLaboratory/docs/adr/001-blueprint-db-access.md (étage 1, hors git).

Approach

Compiler is self-contained — it builds a synthetic MetaData from the SchemaDescriptor rather than asking the service for its own metadata. Services just execute the resulting Select against their async engine and serialise rows. Decision rationale : QueryMe stays a pure library, no service-side wiring contract beyond the Select itself.

Acceptance criteria

  • compile_query(descriptor, schema) -> sqlalchemy.Select returns a working SELECT statement.
  • Synthetic MetaData built from SchemaDescriptor ; closed ColumnType mapped to SQLAlchemy types (String, Text, Integer, Float, Boolean, Uuid, DateTime, Date, JSON).
  • Supports : single FROM, multiple INNER JOINs, AND-joined WHERE, multiple ORDER BY, LIMIT, OFFSET.
  • All 9 WHERE operators implemented : =, !=, >, <, >=, <=, IN, LIKE, IS NULL.
  • Re-validates input via validate_against_schema ; on issues, raises CompilationError carrying the structured issues (no silent failure, no half-built statement).
  • Resolves both unqualified (col) and qualified (table.col) references in WHERE / ORDER / JOIN.
  • Tests cover : every operator, join (single + chained), order, limit/offset, qualified refs, error path with bad descriptor.
  • CI green : ruff clean, mypy strict clean, full pytest suite passes.

Out of scope

  • Mutation (INSERT/UPDATE/DELETE) — Phase 2.x per ADR 001.
  • Ambiguous unqualified column references (same name on multiple joined tables) — currently first-match, will tighten in v0.3 with a validator warning.
  • Type coercion of WHERE values vs column types — delegated to SQLAlchemy / database layer.

Definition of done

PR opened against main, CI green, maintainer reviews and squash-merges. Branch deletion + tag v0.2.0 are maintainer calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions