Skip to content

Added partial BigInt support #471

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

Merged
merged 3 commits into from
Aug 12, 2021
Merged

Added partial BigInt support #471

merged 3 commits into from
Aug 12, 2021

Conversation

kileha3
Copy link
Contributor

@kileha3 kileha3 commented Aug 11, 2021

BigInt is currently not fully supported at WASM level, we have added its support only when getting data from the database.

Moved from es6 to support bigint

Changed from getNumber to getBigInt

Avoided blobal redeclaration of function/variables

Improved BigInt support, handled bind params for bigInt

Logical change on how big int is supported

BigInt is not fully supported at WASM level

Added config to enable and disable bigInt support

Added documentation

Changed var to const as per readme standard
Copy link
Member

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

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

Overall this looks good, thank you !

A few things:

  • Let's stay compatible with es6, just add a dynamic check for BigInt
  • We support environments that don't support the default function argument value syntax.
  • remove dead code
  • it looks like you implemented support for binding BigInts, but added to the README "Binding BigInt is still not supported"
  • We need tests

.eslintrc.js Outdated
@@ -3,7 +3,7 @@
module.exports = {
env: {
browser: true,
es6: true,
es2020: true,
Copy link
Member

Choose a reason for hiding this comment

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

I think we can avoid having to switch to es2020, and keep compatibility with environments without bigint.

You can add

if (typeof BigInt !== "function") throw new Error("BigInt not supported");

before using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, thanks

src/api.js Outdated
pos = this.pos;
this.pos += 1;
}
this.db.handleError(sqlite3_bind_int64(this.stmt, pos, num));
Copy link
Member

Choose a reason for hiding this comment

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

Does this work ? Don't you need to convert the integer to a string for it to pass the wasm frontier ?

Also, isn't this dead code ? The method name isn't quoted so it's not usable from the outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the best option is to remove it since BigInt is not supported at WASM level and yes I think this is a dead code since on bindValue for bigint, bindString is called.

@kileha3
Copy link
Contributor Author

kileha3 commented Aug 11, 2021

Overall this looks good, thank you !

A few things:

  • Let's stay compatible with es6, just add a dynamic check for BigInt
  • We support environments that don't support the default function argument value syntax.
  • remove dead code
  • it looks like you implemented support for binding BigInts, but added to the README "Binding BigInt is still not supported"
  • We need tests

Regarding tests, I tried writing some tests on BigInt and seems like the current test environment wasn't supporting BigInt. What might be the solution to this?

@lovasoa
Copy link
Member

lovasoa commented Aug 11, 2021

Regarding tests, I tried writing some tests on BigInt and seems like the current test environment wasn't supporting BigInt. What might be the solution to this?

Either add setup-node to the CI with a recent node version, and in the tests ignore the test when BigInt is not present.
https://github.com/sql-js/sql.js/tree/master/.github/workflows

Or add a BigInt polyfill in the tests.

@kileha3
Copy link
Contributor Author

kileha3 commented Aug 11, 2021

Regarding tests, I tried writing some tests on BigInt and seems like the current test environment wasn't supporting BigInt. What might be the solution to this?

Either add setup-node to the CI with a recent node version, and in the tests ignore the test when BigInt is not present.
https://github.com/sql-js/sql.js/tree/master/.github/workflows

Or add a BigInt polyfill in the tests.

Working on it, thanks.

@kileha3 kileha3 requested a review from lovasoa August 11, 2021 13:07
src/api.js Outdated
@@ -400,6 +418,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
for (var field = 0; field < ref; field += 1) {
switch (sqlite3_column_type(this.stmt, field)) {
case SQLITE_INTEGER:
var getfunc = config && config.useBigInt
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of config && add config = config || {} at the start of the function. This will make it easier to extend in the future.

Copy link
Contributor Author

@kileha3 kileha3 Aug 11, 2021

Choose a reason for hiding this comment

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

Maybe instead of config && add config = config || {} at the start of the function. This will make it easier to extend in the future.

I think I did miss something, I see an issue on minified files. When we pass config object { useBigInt: true } , config.useBigInt ? .... will always be evaluated as false since object property name useBigInt will be mangled to something like l.Ty. So, it will be something like l.Ty ? .... , of which Ty is not a property of l at run time. Will it be possible to have a way to prevent object properties mangling ? any idea on how to move forward on this?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you should use config["useBigInt"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe instead of config && add config = config || {} at the start of the function. This will make it easier to extend in the future.

Just pushed the changes, thanks

@kileha3 kileha3 requested a review from lovasoa August 11, 2021 18:01
@lovasoa lovasoa merged commit baad65c into sql-js:master Aug 12, 2021
@lovasoa
Copy link
Member

lovasoa commented Aug 12, 2021

Your work is up on npm :) https://www.npmjs.com/package/sql.js

Thanks again for your contribution, @kileha3

@kileha3
Copy link
Contributor Author

kileha3 commented Aug 12, 2021 via email

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