Skip to content

sqlite: typed function/operator surface, unified with the PG codegen#82

Merged
ryanrasti merged 1 commit into
mainfrom
ryan_sqlite_fns
Jul 12, 2026
Merged

sqlite: typed function/operator surface, unified with the PG codegen#82
ryanrasti merged 1 commit into
mainfrom
ryan_sqlite_fns

Conversation

@ryanrasti

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR overhauls the SQLite typed-function surface generation: it replaces the prior runtime-only inference approach with a doc-derived, mechanically verified signatures pipeline, then emits placed methods/free functions with strict @expose runtime argument validation for exoeval/RPC safety.

Changes:

  • Add a doc-backed SQLite signature inventory (signatures.ts + docs/*.json) and a deterministic emitter (emit.ts) that generates the SQLite method/function surface.
  • Add a property-based verifier that checks every signature claim against the actual SQLite engine (signatures.verify.test.ts) and broaden SQLite smoke tests to cover cross-surface composition and runtime gating.
  • Adjust SQLite runtime behavior and surrounding plumbing (new Any root, boolean/int binding normalization, unary-op support, and codegen script updates).

Reviewed changes

Copilot reviewed 31 out of 41 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vitest.config.ts Exclude .claude/ from Vitest scanning.
src/types/sqlite/smoke.test.ts Expands smoke tests to cover generated surface breadth, placement, and runtime schema gating.
src/types/sqlite/signatures.verify.test.ts Adds engine-backed verifier for doc-extracted signatures + completeness/determinism checks.
src/types/sqlite/signatures.ts Loads and validates per-doc-page JSON signature facts + defines EXCLUSIONS policy list.
src/types/sqlite/overrides/real.ts Removes hand-written Real override in favor of generated view class.
src/types/sqlite/overrides/integer.ts Removes hand-written Integer override in favor of generated view class.
src/types/sqlite/overrides/bool.ts Reworks Bool to extend generated bool-subject methods and keep hand-written connectives/statics.
src/types/sqlite/overrides/any.ts Introduces hand-written SQLite root Any over generated universal surface, including bespoke .in().
src/types/sqlite/index.ts Updates SQLite barrel exports (root Any, generated views, and generated free functions).
src/types/sqlite/generated/support.ts Adds shared generation helpers (zod schema builder + numeric result strategy).
src/types/sqlite/generated/bool.ts Adds generated bool-subject method base class (extended by hand-written Bool).
src/types/sqlite/generated/blob.ts Regenerates Blob view class and placed blob-subject methods with strict @expose schemas.
src/types/sqlite/generated/any.ts Adds generated universal-method base class (extended by hand-written Any).
src/types/sqlite/generate.ts Removes legacy runtime-only SQLite inference/emitter script.
src/types/sqlite/emit.ts Adds deterministic emitter that places methods by subject domain and emits free functions + barrel updates.
src/types/sqlite/docs/VERSION Records doc snapshot stamp and target SQLite version.
src/types/sqlite/docs/percentile.json Adds extracted signature facts for percentile extension aggregates.
src/types/sqlite/docs/lang_mathfunc.json Adds extracted signature facts for math functions.
src/types/sqlite/docs/lang_expr.json Adds extracted signature facts for expression operators.
src/types/sqlite/docs/lang_datefunc.json Adds extracted signature facts for datetime functions/modifiers and subject placement.
src/types/sqlite/docs/lang_corefunc.json Adds extracted signature facts for core functions (incl. deterministic vs non-deterministic).
src/types/sqlite/docs/lang_aggfunc.json Adds extracted signature facts for aggregates.
src/types/sqlite/docs/json1.json Adds extracted signature facts for JSON functions/operators.
src/types/sqlite/docs/index.ts Defines the doc-extraction schema/contract and extraction prompt used to produce docs/*.json.
src/types/sqlite/docs/fetch.sh Adds script to vendor SQLite doc pages and stamp VERSION.
src/types/sqlite/docs/.gitignore Ignores vendored .html doc pages (JSON artifacts remain committed).
src/types/sqlite/base.ts Removes legacy SqliteValue base class (replaced by SQLite Any).
src/types/runtime.ts Adds UnaryOp support for dialect-tagged unary operator AST construction.
src/tables/sqlite.ts Updates affinity resolution to map NUMERIC fallthrough to Any (new SQLite root).
src/tables/sqlite.test.ts Updates tests and generated-code snapshot expectations for Any vs SqliteValue.
src/tables/generate.ts Updates documentation/comments for resolved SQLite type class naming.
src/exoeval/tool.ts Adds expose.rest(...) / RestSchema support for variadic argument validation.
src/driver.ts Normalizes better-sqlite3 bindings: integers as BigInt and booleans as 0n/1n for correct storage/semantics.
src/builder/query.ts Updates comments to reflect SQLite Any as the common SqlValue-based dialect root.
package.json Switches SQLite codegen scripts from generate.ts to emit.ts.
.gitignore Ignores .claude/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/types/sqlite/overrides/any.ts Outdated
Comment on lines +51 to +55
in(...vals: [Any<any> | boolean | number | string, ...(Any<any> | boolean | number | string)[]]): types.Bool<any> {
const wrapped = vals.map((v) => {
if (v instanceof Any) {return v;}
if (!isPlainData(v)) {
const name = (Object.getPrototypeOf(v) as { constructor?: { name?: string } } | null)?.constructor?.name ?? "anonymous";
Comment thread src/types/sqlite/signatures.verify.test.ts Outdated
Comment thread src/types/sqlite/signatures.verify.test.ts Outdated
Comment thread src/types/sqlite/emit.ts Outdated

const HEADER = "// Auto-generated by src/types/sqlite/emit.ts from signatures.ts — do not edit.\n";

const CLS: Record<SqlT, string> = {
Comment thread src/types/sqlite/emit.ts Outdated
const CLS: Record<SqlT, string> = {
integer: "Integer", real: "Real", text: "Text", blob: "Blob", bool: "Bool", any: "Any",
};
const PRIM: Record<SqlT, string> = {

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 46 changed files in this pull request and generated 3 comments.

Comment thread src/types/sqlite/overrides/blob.ts Outdated
Comment on lines +1 to +4
// BLOB storage-class view — hand-written behavior over the generated
// method surface (../generated/blob.ts): Uint8Array instances are the
// accepted primitive (instanceof, not typeof), and the driver hands
// blobs back as Uint8Array — the declare only narrows the return type.
Comment on lines +7 to +10
export class Blob<in out N extends number> extends Generated<N> {
static override acceptsPrimitive(v: unknown): boolean { return v instanceof Uint8Array; }
declare deserialize: (raw: string) => Uint8Array;
}
Comment thread src/types/sql-value.ts
Comment on lines 170 to 172
throw new Error(
`${this.__typnameText}.serialize: expected a ${this.__typnameText} instance or ${expected} primitive, got ${typeof v} (${String(v).slice(0, 60)}).`,
`${this.__typnameText}.serialize: expected a ${this.__typnameText} instance or ${this.primitiveTs} primitive, got ${typeof v} (${String(v).slice(0, 60)}).`,
);
Both pg and sqlite feed one emitter a typed schema of facts describing
their function catalog.

pg's facts are auto-generated on the fly from pg_catalog (as before —
generated output is byte-identical).

sqlite's facts are generated by running an LLM over the sqlite docs
pages, committed as JSON, and sanity-checked against the real engine
with deterministic quick-check-style tests.
@ryanrasti ryanrasti merged commit ef67429 into main Jul 12, 2026
3 checks passed
@ryanrasti ryanrasti changed the title Thorough code generation for sqlite built-in functions sqlite: typed function/operator surface, unified with the PG codegen Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants