Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rytido opened this issue May 2, 2024 · 1 comment
Closed

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

rytido opened this issue May 2, 2024 · 1 comment

Comments

@rytido
Copy link

rytido commented May 2, 2024

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
Copy link
Owner

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',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants