Skip to content

Sqlite objects#33

Merged
cs01 merged 6 commits intomainfrom
sqlite-objects
Feb 22, 2026
Merged

Sqlite objects#33
cs01 merged 6 commits intomainfrom
sqlite-objects

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Feb 22, 2026

Add sqlite.query() — typed object array returns

sqlite.all() returns string[] where multi-column rows are pipe-delimited ("1|Alice|NYC"), requiring .split("|") and positional indexing. sqlite.query() returns typed object arrays instead, enabling direct field access:

interface Post { id: string; title: string; url: string; }
const rows: Post[] = sqlite.query(db, "SELECT id, title, url FROM posts");
console.log(rows[0].title);  // direct field access, no split

How it works

  • New LLVM IR helper @__sqlite_row_to_struct converts each row into a flat struct of i8* fields (one strdup'd column per field), replacing the pipe-delimited string builder
  • @__sqlite_query and @__sqlite_query_params mirror the existing @__sqlite_all / @__sqlite_all_params helpers but return %ObjectArray* instead of %StringArray*
  • The variable allocator's existing declaredType fallback handles the Post[] → interface metadata wiring automatically — no generics needed

Changes

File Change
src/codegen/stdlib/sqlite.ts generateQuery(), 3 new IR helpers, canHandle() updated
src/codegen/expressions/method-calls.ts "query" dispatch case
src/codegen/infrastructure/generator-context.ts ISqliteGenerator interface + mock
src/codegen/llvm-generator.ts Emit 3 new helpers conditionally
tests/fixtures/builtins/sqlite-query.ts New test fixture
.claude/rules.md Updated for @test auto-discovery, C bridges, stale compiler, worktree setup

Test plan

  • npm run build — TypeScript compiles clean
  • npm test — 199/199 tests pass (including new sqlite-query fixture)
  • Self-hosting passes (Stage 0 + Stage 1)
  • Test covers: basic multi-row query, parameterized query, empty result set

@cs01 cs01 merged commit 50cf01c into main Feb 22, 2026
14 checks passed
@cs01 cs01 deleted the sqlite-objects branch February 22, 2026 17:36
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.

1 participant