postguard
postguard copied to clipboard
Validating TypeScript types vs. database types
I'm not sure if this is something that postguard handles.
I have a table like this:
CREATE TABLE users (
id uuid PRIMARY KEY DEFAULT gen_random_uuid (),
name text NOT NULL,
);
Then in my code:
const usersTable = defineTable('users', {
id: Schema.Number,
name: Schema.String,
});
type UserRecord = TableRow<typeof usersTable>;
console.log(await pool.query<UserRecord>(
sql`SELECT id, name FROM users WHERE name = 'test'`,
));
Postguard sees no issues here. I was hoping it would fail since I defined id
in the table as Schema.Number
but the data type of the id
column is uuid
which is parsed as a string
by node-postgres
. Am I doing something wrong or this is not supported / not how it works?
Once more, sorry for the delayed response.
Yes, postguard should handle that (I would expect it to). I am not sure if postguard checks static values in queries, since it's been some time that I wrote that code. Need to check on that, but that would explain it.