diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index fb229e19fd6aef..0583b284cb8437 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2257,10 +2257,11 @@ bool StatementSync::BindParams(const FunctionCallbackInfo& args) { bool StatementSync::BindValue(const Local& value, const int index) { // SQLite only supports a subset of JavaScript types. Some JS types such as - // functions don't make sense to support. Other JS types such as booleans and + // functions don't make sense to support. Other JS types such as // Dates could be supported by converting them to numbers. However, there // would not be a good way to read the values back from SQLite with the - // original type. + // original type. JS Boolean binds to 1 and 0 because SQLite maps true and + // false keywords to 1 and 0. Isolate* isolate = env()->isolate(); int r; if (value->IsNumber()) { @@ -2293,6 +2294,8 @@ bool StatementSync::BindValue(const Local& value, const int index) { buf.data(), static_cast(buf.length()), SQLITE_TRANSIENT); + } else if (value->IsBoolean()) { + r = sqlite3_bind_int(statement_, index, value->IsTrue() ? 1 : 0); } else if (value->IsBigInt()) { bool lossless; int64_t as_int = value.As()->Int64Value(&lossless); diff --git a/test/parallel/test-sqlite-data-types.js b/test/parallel/test-sqlite-data-types.js index 26af15a777d234..969be3d6417904 100644 --- a/test/parallel/test-sqlite-data-types.js +++ b/test/parallel/test-sqlite-data-types.js @@ -80,6 +80,9 @@ suite('data binding and mapping', () => { text: '', buf: new Uint8Array(), }); + + t.assert.deepStrictEqual(stmt.run(5, true, false, true, null), { changes: 1, lastInsertRowid: 5 }); + t.assert.deepStrictEqual(query.get(5), { __proto__: null, key: 5, int: 1, double: 0, text: '1', buf: null }); }); test('large strings are bound correctly', (t) => {