Skip to content

Commit

Permalink
Same boolean handling in better-sqlite3 as in sqlite3 (#4982)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Cavadenti <olivier.cavadenti@gmail.com>
  • Loading branch information
toBeOfUse and OlivierCavadenti committed Jan 31, 2022
1 parent f50554b commit f9f6a38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/better-sqlite3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Client_BetterSQLite3 extends Client_SQLite3 {
}

if (typeof binding === 'boolean') {
return String(binding);
return Number(binding);
}

return binding;
Expand Down
16 changes: 16 additions & 0 deletions test/integration2/schema/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,22 @@ describe('Schema (misc)', () => {
'create index "10_test_table_logins_index" on "10_test_table" ("logins")',
]);
}));

it('test boolean type with sqlite3 and better sqlite3 #4955', async function () {
if (!isSQLite(knex)) {
this.skip();
}
await knex.schema
.dropTableIfExists('test')
.createTable('test', (table) => {
table.boolean('value').notNullable();
});

await knex('test').insert([{ value: true }, { value: false }]);
const data = await knex('test').select();
expect(data[0].value).to.eq(1);
expect(data[1].value).to.eq(0);
});
});

describe('table', () => {
Expand Down

0 comments on commit f9f6a38

Please sign in to comment.