Generated insert method takes in string but returns integer
woowenjun99 opened this issue · 5 comments
- In my table, I have a field that is of type
INTEGER. - When I generate the code that takes in the field to be inserted into the database, I need to specify it as a string.
- Upon INSERT, the value is inserted into the database as a number.
- My SQLC command for the insert expects a
return :oneand the same field returns an integer.
Example
-- name: CreateOne :one
INSERT INTO table (something) VALUES ($1) RETURN *;The function createOne is generated, but the type for something field during insert is incorrect (in this case a string rather than an integer). However, the return type is a number which is correct.
Even though it is not a big issue, it causes some inconvenience.
Can you try casting $1 to text? I think this will give you the string input type you're looking for.
-- name: CreateOne :one
INSERT INTO table (something) VALUES ($1::text) RETURN *;
Thanks for the quick reply! My schema looks something like this:
CREATE TABLE "products" (
"id" TEXT NOT NULL,
"quantity" INTEGER NOT NULL,
CONSTRAINT "products_pkey" PRIMARY KEY ("id")
);What was generated looks something like this:
export interface CreateProductArgs {
id: string;
quantity: string;
}
export interface CreateProductRow {
id: string;
quantity: number;
}Not sure if the typing is intended
@woowenjun99 Thanks for providing your schema. I misunderstood the issue at first but have now reproduced it locally.
Can you confirm that things are now working with 0.1.2?
version: '2'
plugins:
- name: ts
wasm:
url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.2.wasm
sha256: f8b59cdd78b35fae157a95c5813cb09b1ebdd9a31acf2d7015465539986ccd2bHi yeap it seems to be working! TYSM