Docs / Reference
Claim contract: code-to-table access
The claim contract of the code-to-table extractor (ADR 0060) as recorded when it was
designed (task T018h, internal record). docs/extract/table-access.md and the code
table in internal/extract/tableaccess must equal these rows (TestTableAccessContract).
Claim contract
Row kinds: P Python (SQLModel/SQLAlchemy), R Prisma, Z
Drizzle, S sqlx, Q the SQL subset reader shared by every SQL
carrier, D the single default branch. Every form the corpora use has
exactly one row (counts per row: the T018h inventory (internal record)); CT-S2
and CT-P2's insert are fixture-only. The contract test keeps
docs/extract/table-access.md, the Go table and the code 1:1 (T018
plan, shared piece 4: Go table equals the docs table, a branch per claim
row and a row per branch, the tags emitted over the fixtures equal the
claim rows, each listed form of a multi-form row reached). 17 rows: 16
rows plus D; CT-Q1 and CT-Q2 are reached through the SQL carriers
(P5, R3, Z4, S1, S2) and tagged alongside them.
| id | form | claim | refusal / unknown | assumptions |
|---|---|---|---|---|
| CT-P1 | select(E, ...) resolved to sqlmodel.select or sqlalchemy.select (also sqlalchemy.future, sqlmodel.sql.expression), with entities a model class, a model column M.c, col(M.c), or aliased(M); chained .select_from(M), .join(M[, on]), .outerjoin(M), .join_from(A, B) on the same chain |
reads_table to each model table (operation: select); fact (no receiver involved) |
an entity or join target that is not a resolved model (func.count() without select_from, t.c.x of a Core Table, a CTE or subquery .c, a parameter): no claim for it, unknown record (partial when another entity is claimed); no claimed entity: unknown; a model referenced only in .where()/.order_by() (implicit FROM): not claimed (follow-up) |
TA-V2 |
| CT-P2 | insert(M), update(M), delete(M) resolved to sqlmodel/sqlalchemy (also sqlalchemy.dialects.postgresql.insert, ...sqlite.insert), any chain (.where, .values, .on_conflict_do_update, .returning) |
writes_table to M (insert/update/delete; on_conflict_do_update: upsert); fact |
target not a resolved model (a Core Table, sa.table("n", ...)): unknown; insert(M).from_select(cols, select(...)): the inner select is its own CT-P1 site |
TA-V2 |
| CT-P3 | <r>.get(M, ...), <r>.get_one(M, ...) with M a resolved model class |
reads_table to M (get); fact when <r> is a parameter annotated with a name resolving to sqlmodel.Session, sqlalchemy.orm.Session, sqlalchemy.ext.asyncio.AsyncSession or sqlmodel.ext.asyncio.session.AsyncSession, else inferred (assumes: TA-V3c) |
first argument not a resolved model: no site (not recognised; dict.get and the like) |
TA-V2, TA-V3c |
| CT-P4 | <r>.add(o), <r>.delete(o), <r>.merge(o), <r>.refresh(o), <r>.add_all([o, ...]) (list literal), with the class of each o proven: an inline M(...), M.model_validate(...), M.from_orm(...) (deprecated alias), a local name with one unconditional assignment from one of those in the same function, or a parameter annotated M, M | None or Optional[M] |
writes_table to M (add, delete, merge), reads_table (refresh); fact/inferred as CT-P3 |
the class of o not proven (a loop variable, a query result, another call, an outer variable, an unannotated parameter), add_all of anything but a list literal of proven objects: unknown (object_class_unproven) |
TA-V2, TA-V3c |
| CT-P5 | text("<literal>") resolved to sqlalchemy.text/sqlmodel.text, the literal a plain string (concatenation of literals allowed) |
the SQL subset reader (CT-Q1, CT-Q2) over the literal, against the SQLModel group's tables (__tablename__, else the class name lower-cased, as T018c2 names them); every edge inferred (assumes: TA-V1), tool: "sql" |
an f-string, %/.format or a non-literal argument: unknown (sql_not_literal); the reader's refusals |
TA-V1, TA-V4 |
| CT-R1 | <r>.<delegate>.<op>(args) in a package with exactly one Prisma group whose models include Delegate (delegate = model name with its first letter lower-cased); op read: findUnique, findUniqueOrThrow, findFirst, findFirstOrThrow, findMany, count, aggregate, groupBy; write: create, createMany, createManyAndReturn, update, updateMany, updateManyAndReturn, upsert, delete, deleteMany |
reads_table or writes_table to the model table (find, count, aggregate, insert, update, upsert, delete); always inferred (assumes: TA-V3a; receivers are this.prisma, an imported module object, tx) |
<r>[expr].<op> (dynamic delegate): unknown with the group's tables as candidates; an op outside the lists ($extends model methods): no site; a delegate that is not a model: no site |
TA-V2, TA-V3a |
| CT-R2 | in a CT-R1 site's argument object: relation fields of the model (from the Prisma group) under include, select or a relation filter (some, every, none, is, isNot) in where, nested at any depth; under data, a relation field with create, createMany, connectOrCreate, upsert, update, updateMany, delete, deleteMany |
reads_table to each related model read; writes_table to each related model nested-written; same provenance as its CT-R1 site |
an object with a spread (Spread, payload 1): partial unknown; connect, disconnect, set (the table holding the key depends on the relation side; implicit many-to-many writes the join table): unknown for that relation (relation_write_side); a key that is not a relation field: nothing |
TA-V2, TA-V3a |
| CT-R3 | <r>.$queryRaw..., `<r>.$executeRaw`... (tagged; substitutions are bound parameters by Prisma's semantics), <r>.$queryRawUnsafe("<literal>", ...), <r>.$executeRawUnsafe("<literal>", ...) |
the SQL subset reader over the text (a substitution read as a parameter $n), against the package's Prisma group tables (@@map name, else the model name; @@schema, else public); inferred (assumes: TA-V1, TA-V3a), tool: "sql" |
a non-literal argument, Prisma.sql/Prisma.raw/Prisma.join fragments (hoppscotch binds them to locals): unknown (sql_not_literal); the reader's refusals |
TA-V1, TA-V3a, TA-V4 |
| CT-Z1 | <r>.select(...), .selectDistinct(...), .selectDistinctOn(...) followed on the chain by .from(t); .leftJoin(t, ...), .innerJoin, .rightJoin, .fullJoin, .crossJoin (and ...Lateral); <r>.$count(t); with t a table const of a Drizzle group of the package (W7), resolved as the Targets table says |
reads_table to each t (select, count); inferred (assumes: TA-V3b) |
t a subquery (.as("x")), a $with CTE, a view, a parameter of a generic helper, or anything else unresolved: no claim for it, unknown (partial when another table is claimed) |
TA-V2, TA-V3b |
| CT-Z2 | <r>.insert(t), <r>.update(t) (with .from(u): also reads u), <r>.delete(t), any chain (.values, .set, .where, .onConflictDoUpdate, .onConflictDoNothing, .returning) |
writes_table to t (insert, update, delete; onConflictDoUpdate: upsert); reads_table to u; inferred (assumes: TA-V3b) |
as CT-Z1; insert ... select is .insert(t).select(qb) (Revision 4): the inner chain is its own CT-Z1 site |
TA-V2, TA-V3b |
| CT-Z3 | <r>.query.<key>.findMany(cfg), .findFirst(cfg), where key is the exported name of a table const in the schema modules of exactly one Drizzle group of the package (kaneo and dokploy pass import * as schema); with: { rel: ... } nested at any depth, rel an entry of the table's orm_relations (DR-R1) |
reads_table to the key's table and to each with relation's target (find); inferred (assumes: TA-V3b) |
a key that is no table const or is one in two groups: unknown; a with key not in orm_relations, a cfg with a spread: partial unknown; defineRelations (1.x): D |
TA-V2, TA-V3b |
| CT-Z4 | <r>.execute(sql...), and on sqlite <r>.run, .all, .get, .values with an sql tagged template resolved to drizzle-orm's sql |
the SQL subset reader over the template, where a substitution in a value position is a parameter and a substitution in a table position (CT-Q1) that resolves to a table const of the group is that table; against the package's Drizzle group tables (name, pgSchema, else public); inferred (assumes: TA-V1, TA-V3b), tool: "sql" |
sql.raw(...), sql.identifier(...), a substitution in a table position that is no table const, any other structural substitution: unknown (sql_dynamic); the reader's refusals |
TA-V1, TA-V3b, TA-V4 |
| CT-S1 | sqlx::query!, query_as!, query_scalar! and their _unchecked forms (path sqlx::<m>! or <m>! imported by use sqlx::...), first string argument a literal (after the record type for query_as!) |
the SQL subset reader over the literal against the sqlx migration set of the same Cargo package (T018a discovery); fact (sqlx checks the text against the migrated database at compile time), tool: "sqlx" |
the package has no readable migration set, or the set is wholly opaque: unknown (no_schema_source); the reader's refusals |
TA-V1, TA-V4 |
| CT-S2 | functions sqlx::query("<lit>"), query_as::<_, T>("<lit>"), query_scalar("<lit>"), query_with/query_as_with with a literal (fixture-only: 0 corpus sites) |
as CT-S1, but inferred (assumes: TA-V1): unlike the macros, the text is not checked at compile time |
a non-literal argument (&format!(...), a variable): unknown (sql_not_literal) |
TA-V1, TA-V4 |
| CT-Q1 | SQL subset reader (no claim of its own; tagged with its carrier): one statement (an optional trailing ;), comments ignored, kinds SELECT, INSERT, UPDATE, DELETE, WITH (writable CTEs included); table references after FROM, JOIN, comma joins, INSERT INTO t [(cols)] (VALUES or SELECT), UPDATE t ... [FROM ...], DELETE FROM t [USING ...], in subqueries at any depth, [ONLY] [schema.]name with an optional alias; ON CONFLICT ... DO NOTHING / DO UPDATE (EXCLUDED is not a table), RETURNING, lock clauses FOR UPDATE / NO KEY UPDATE / SHARE / KEY SHARE |
writes: the INSERT, UPDATE and DELETE targets; reads: every other reference; a lock clause reads; the UPDATE/DELETE target is not also read; function calls in FROM (unnest(...), set-returning functions) are no tables |
another statement kind (DDL, COPY, CALL, SET, LOCK, DO, EXPLAIN, MERGE), several statements, LATERAL function forms the reader cannot delimit, a parse failure: unknown (sql_outside_subset); a statement with no table reference (select now()): no claim, no unknown |
TA-V4 |
| CT-Q2 | name resolution for CT-Q1 references | an unqualified name: a CTE of the statement shadows it (no claim); else public.<name> folded to lower case unless quoted; a qualified name: that schema; claimed when exactly one table of the carrier's schema source has that schema and name (migration set: the tables it holds at its end; model groups: their tables) |
a name found in no table of the source (a view, a table created outside the set, a typo): unknown (sql_name_unresolved, the name in the reason); a migration set whose opaque statements may create tables (set_opaque_statements > 0) and a name not found: unknown; a name two sources of the package hold: unknown (ambiguous_group) |
TA-V4 |
| D | anything else: legacy session.query(M) and Flask-SQLAlchemy M.query (0 corpus sites), SQLAlchemy Core Table objects, driver-level cursor.execute("...")/conn.execute("...") (sqlite3, asyncpg), app helpers that wrap SQL or models (umami rawQuery/pagedQuery), generic repository helpers whose table is a parameter, query_file!, Prisma $extends methods, Drizzle 1.x forms, Diesel, GORM, Sequelize, TypeORM |
nothing; an SQL-shaped string literal (^\s*(select|insert|update|delete|with)\b with from, into or set) passed to any call in a captured file adds an unknown record (sql_carrier_unmodelled); every other D form is invisible |
always | - |
Rows CT-Q1 and CT-Q2 have no branch of their own; their refusals are reasons the carriers' unknown records name. The claim side rows are CT-P1..P5, R1..R3, Z1..Z4, S1, S2 (fourteen); Q1 and Q2 are reached through the five SQL carriers.
Report a problem with this pageSource: docs/contract/claims/table-access.md