porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.03k stars 255 forks source link

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

Closed rytido closed 1 month ago

rytido commented 2 months ago

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 } ]

porsager commented 1 month ago

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' https://github.com/porsager/postgres/blob/cc688c642fc98c4338523d3e281e03bf0c3417b8/src/types.js#L25