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

Add option to cast booleans? #932

Open
alexpetros opened this issue Jan 4, 2023 · 2 comments
Open

Add option to cast booleans? #932

alexpetros opened this issue Jan 4, 2023 · 2 comments

Comments

@alexpetros
Copy link

Issue #907 was caused by a problem I come across at runtime occasionally: inserting boolean values into SQLite raises a TypeError because a boolean is not a number, string, bigint, buffer, or null. I understand that this is a design decision to keep the better-sqlite3 interface symmetrical with the SQLite interface, which seems reasonable to me.

However, would you consider a PR that added an option (probably here) to automatically cast booleans to their SQLite equivalent (0 or 1)? SQLite itself will convert the keywords true and false to their integer equivalents, which is in keeping with the loose typing philosophy.

@mceachen
Copy link
Member

This certainly was a stumbling block for me when I first started using better-sqlite3 (followed by my surprise that SQLite had no native support for boolean or date types!).

I think @JoshuaWise 's comment still holds, though: if we automatically converted boolean bound values, it would be potentially (very) surprising when you get back a 0|1 from the same row. I don't see a straightforward heuristic to supporting this.

@alexpetros
Copy link
Author

if we automatically converted boolean bound values, it would be potentially (very) surprising when you get back a 0|1 from the same row. I don't see a straightforward heuristic to supporting this.

You could say the same thing about SQLite itself, which does exactly this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants