porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is insert/update to a boolean supported for truthy strings?

rytido opened this issue · comments

Based on the postgres docs and the parse function I could find, I would expect this to result in a true. Am I missing something?

sql.begin(async (sql) => {
  await sql`create temp table t(boolcol boolean)`;
  const x = { boolcol: "t" };
  await sql`insert into t ${sql(x)}`;
  await sql`update t set ${sql(x)}`;
  console.log(await sql`select boolcol from t`);
});

Result(1) [ { boolcol: false } ]

The parse function is what is used when values is retrieved from the db, so you should look at the serialize function for what is sent serialize: x => x === true ? 't' : 'f'

serialize: x => x === true ? 't' : 'f',