Skip to content

Conversation

@donbernar
Copy link

Sqlite's driver was not generating types properly, it was returning all columns as any attributes instead of inferring the type from the schema.

Here's an example:

-- schema.sql CREATE TABLE tenants ( id TEXT PRIMARY KEY, name TEXT NOT NULL, slug TEXT NOT NULL UNIQUE, deleted INTEGER NOT NULL DEFAULT 0, company_tin TEXT NOT NULL UNIQUE );

Source file:

-- name: Find :one SELECT * FROM tenants WHERE id = ?;

Generated code:

// ... export interface FindArgs { id: any; } export interface FindRow { id: any; name: any; slug: any; deleted: any; companyTin: any; } // ...

When debugging the driver I noticed the received Column in the columnType method where:

const example1 = { name: "id", notNull: true, isArray: false, comment: "", length: -1, isNamedParam: false, isFuncCall: false, scope: "", table: { catalog: "", schema: "", name: "tenants" }, tableAlias: "", type: { catalog: "", schema: "", name: "TEXT" }, isSqlcSlice: false, originalName: "id", unsigned: false, arrayDims: 0, }; const example2 = { name: "deleted", notNull: true, isArray: false, comment: "", length: -1, isNamedParam: false, isFuncCall: false, scope: "", table: { catalog: "", schema: "", name: "tenants" }, tableAlias: "", type: { catalog: "", schema: "", name: "INTEGER" }, isSqlcSlice: false, originalName: "deleted", unsigned: false, arrayDims: 0, };

I decided to convert the column.type.name to lowercase and add TEXT and VARCHAR types to the switch case. After building the wasm module, I run it with examples/sqlc.dev.yaml config file and the example file got updated.

@donbernar
Copy link
Author

donbernar commented Oct 8, 2025

While working on this I noticed the Makefile is not compatible with the latest javy CLI version. I have not updated it in the PR, but changing line 8 with the following solved the issues:

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant