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.sqlCREATETABLEtenants ( id TEXTPRIMARY KEY, name TEXTNOT NULL, slug TEXTNOT NULL UNIQUE, deleted INTEGERNOT NULL DEFAULT 0, company_tin TEXTNOT NULL UNIQUE );

Source file:

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

Generated code:

// ...exportinterfaceFindArgs{id: any;}exportinterfaceFindRow{id: any;name: any;slug: any;deleted: any;companyTin: any;}// ...

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

constexample1={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,};constexample2={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 freeto 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

@donbernar