sqlite: getRow(), parameterized query types/docs, fix interface method_call alloc#96
Merged
sqlite: getRow(), parameterized query types/docs, fix interface method_call alloc#96
Conversation
… for sqlite.query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sqlite: getRow(), parameterized query types/docs, fix interface method_call alloc
What changed
New API:
sqlite.getRow<T>(db, sql, params?)Returns the first matching row as a typed struct, or
nullif no row found. Fills the gap betweensqlite.get()(string, single-row) andsqlite.query()(array, multi-row):Parameterized queries now visible in type definitions
chadscript.d.tswas missing the optionalparams?arg onexec,get, andall, andsqlite.query<T>()wasn't declared at all — even though both had been implemented. Fixed:Bug fix:
getDeclaredInterfaceTyperejects method_call RHSinterface-allocator.tshad a guard that only allowedvariableorobjectas RHS types when resolvingconst x: SomeInterface = <expr>. This blockedmethod_callexpressions (likesqlite.getRow(), or any user function returning an interface) from being tracked as typed interface variables. Field access on the result (alice.name) would fall back to treating the pointer as a raw string.Fix: also allow
method_callin the guard. The subsequentgetInterface(declaredType)check ensures only known interfaces are matched.This is a general fix — any pattern
const x: MyInterface = someMethod()now correctly tracksxasMyInterfaceand generates proper GEP field accesses.Docs:
docs/stdlib/sqlite.mdrewrittenopen,exec,get,getRow,all,query,close).split('|')" tip withsqlite.query()/sqlite.getRow()guidanceexamples/query.tsupdatedUses
sqlite.query<User>()andsqlite.getRow<User>()instead ofsqlite.all()with pipe-delimited output.Test coverage
tests/fixtures/builtins/sqlite-get-row.ts— new fixture covering:getRowwith params (found row, typed field access)getRowreturning null (no match)getRowwithout paramsExisting
sqlite-test.tsandsqlite-query.tscontinue to passNotes
sqlite.get()andsqlite.all()pipe-delimited behavior is unchanged (backwards compatible)getRowrequires explicit type annotation (const x: MyInterface = sqlite.getRow(...)) for field access to work — the generic type param alone isn't enough since ChadScript uses type erasure