-
Notifications
You must be signed in to change notification settings - Fork 83
Permit JS booleans to be bound to queries, as integer 0/1 values #272
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
Conversation
There was a problem hiding this 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.
- Added a case to handle boolean values, binding them as integers (1 for true, 0 for false) using
- test/api_statements.js
- Added a new test case
should bind booleanto verify that boolean values are correctly bound to queries and retrieved as integers.
- Added a new test case
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
-
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. ↩
There was a problem hiding this 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
falseboolean value: A test case withstoreValueset tofalseshould 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.
| 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); | ||
| } | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test case with storeValue set to false to ensure that false boolean values are correctly bound as 0.
| 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); | |
| } | |
| } | |
| }); |
|
Thanks for the PR! I'm not coming up with any downside to this. Unless I do, I'll probably merge it as-is. |
…shimoto#272) * Permit boolean values to be bound to statements, as 0/1 * Add test for boolean binding
* 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>
While SQLite does not recognize booleans as a separate data type (https://sqlite.org/datatype3.html), it does support
BOOLcolumn types, and the magic stringsTRUEandFALSE, which actually store an integer 0 or 1. It seems useful to permit JS booleans to be bound to queries to support this.Checklist
non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
derivative works of, publicly display, sublicense, and distribute this
Contribution and such derivative works.
Contribution contains no content requiring a license from any third party.