Skip to content

Conversation

@grantcox
Copy link
Contributor

@grantcox grantcox commented May 13, 2025

While SQLite does not recognize booleans as a separate data type (https://sqlite.org/datatype3.html), it does support BOOL column types, and the magic strings TRUE and FALSE, which actually store an integer 0 or 1. It seems useful to permit JS booleans to be bound to queries to support this.

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @grantcox, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request enables the binding of JavaScript boolean values to SQLite queries. Since SQLite represents booleans as integers (0 or 1), this change allows JS booleans to be seamlessly used in queries. The pull request includes a modification to src/sqlite-api.js to handle boolean types and a new test case in test/api_statements.js to verify the functionality.

Highlights

  • Feature: Added support for binding JavaScript boolean values to SQLite queries as integers (0 or 1).
  • Testing: Included a new test case to ensure boolean values are correctly bound and retrieved from the database.

Changelog

  • src/sqlite-api.js
    • Added a case to handle boolean values, binding them as integers (1 for true, 0 for false) using sqlite3.bind_int.
  • test/api_statements.js
    • Added a new test case should bind boolean to verify that boolean values are correctly bound to queries and retrieved as integers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A boolean's plight,
In SQLite's dim light,
Zero or one it seems,
A coder's waking dreams,
Binding true, making it right.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to bind JavaScript boolean values to SQLite queries as integer 0/1 values, which aligns with SQLite's handling of boolean data. The changes include an update to sqlite-api.js to handle boolean types and a new test case in api_statements.js to verify the functionality. Overall, the changes seem reasonable and well-tested.

Summary of Findings

  • Missing test case for false boolean value: A test case with storeValue set to false should be added to ensure that false boolean values are correctly bound as 0.

Merge Readiness

The pull request is in good shape and introduces a useful feature. Addressing the suggested improvements, such as adding a comment and a test case for false boolean values, would further enhance the code quality. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

Comment on lines +241 to +260
it('should bind boolean', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = true;
const expectedRetrievedValue = 1;

for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);

while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);

expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a test case with storeValue set to false to ensure that false boolean values are correctly bound as 0.

Suggested change
it('should bind boolean', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = true;
const expectedRetrievedValue = 1;
for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);
while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);
expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});
it('should bind boolean false', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = false;
const expectedRetrievedValue = 0;
for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);
while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);
expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});

@rhashimoto
Copy link
Owner

Thanks for the PR! I'm not coming up with any downside to this. Unless I do, I'll probably merge it as-is.

@rhashimoto rhashimoto merged commit 7d45baf into rhashimoto:master May 17, 2025
1 check passed
xesrevinu pushed a commit to effect-anything/wa-sqlite that referenced this pull request Jul 3, 2025
…shimoto#272)

* Permit boolean values to be bound to statements, as 0/1

* Add test for boolean binding
rhashimoto added a commit to team-reflect/wa-sqlite that referenced this pull request Sep 24, 2025
* Fix resetting isHandleRequested

* Bump package version.

* Fix hello demo import paths.

* Permit JS booleans to be bound to queries, as integer 0/1 values (rhashimoto#272)

* Permit boolean values to be bound to statements, as 0/1

* Add test for boolean binding

* Using a single TextEncoder for all string conversions

* Export HEAP* module members for recent EMSDK changes.

* Bump tar-fs from 3.0.8 to 3.0.9

Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.0.8 to 3.0.9.
- [Commits](mafintosh/tar-fs@v3.0.8...v3.0.9)

---
updated-dependencies:
- dependency-name: tar-fs
  dependency-version: 3.0.9
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update SQLite to 3.50.1.

* Bump package version.

* Update issue templates

* Replace Facade Proxy with handwritten proxy. (rhashimoto#285)

* Replace Proxy with handwritten proxy for jRead/jWrite buffers.

* Replace Proxy with handwritten proxy for VFS return data.

---------

Co-authored-by: Roy Hashimoto <[email protected]>

* Use non-CAPTCHA SQLite download URL. (rhashimoto#289)

* Use non-CAPTCHA SQLite download URL.

* Use consistent Makefile variable bracing.

---------

Co-authored-by: Roy Hashimoto <[email protected]>

* Fix WebLocksMixin state initialization. (rhashimoto#293)

* Fix WebLocksMixin state initialization.

* Don't fetch state in WebLocksMixin file control unnecessarily.

* Minor fixes.

---------

Co-authored-by: Roy Hashimoto <[email protected]>

* Bump package version.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Simon Binder <[email protected]>
Co-authored-by: Roy Hashimoto <[email protected]>
Co-authored-by: Grant Cox <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

2 participants