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

Booleans in better-sqlite3 #4955

Closed
joshkel opened this issue Jan 21, 2022 · 2 comments
Closed

Booleans in better-sqlite3 #4955

joshkel opened this issue Jan 21, 2022 · 2 comments

Comments

@joshkel
Copy link

joshkel commented Jan 21, 2022

Environment

Knex version: 1.0.1
Database + version: better-sqlite3 7.4.6
OS: macOS 12.1

Bug

I'm trying out the new better-sqlite3 driver in Knex 1.x (due to the maintenance questions I saw with sqlite3 and @vscode/sqlite3). I ran into a problem within my application's code: Knex's better-sqlite3 driver encodes booleans as string literals ('true' and 'false'), instead of as 0 and 1. This seems like a bug:

  • It's incompatible with Knex's sqlite3 driver, so the better-sqlite3 driver can't be used as a drop-in replacement.
  • It's inconsistent with SQLIte's documentation.
  • 0 and 1 are truthy and falsy in JavaScript, so they can often be used without further processing; both 'true' and 'false' are truthy.
const knex = require('knex');

async function main() {
  for (const client of ['sqlite3', 'better-sqlite3']) {
    console.log('Testing ' + client);

    const db = knex({ client, connection: ':memory:', useNullAsDefault: true });
    await db.schema.createTable('test', (table) => {
      table.boolean('value').notNullable();
    });

    await db('test').insert([{ value: true }, { value: false }]);
    console.log(await db('test').select());

    await db.destroy();
    console.log();
  }
}

main();
@toBeOfUse
Copy link
Contributor

(For future reference, this issue is fixed in PR #4982, it can now be closed at the maintainers' convenience I believe, thanks @joshkel for finding and linking to the exact line of code that had to be changed)

@kibertoad
Copy link
Collaborator

Released in 1.0.2

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

3 participants