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

feat: Add sql.js fallback for sqlite in wasm #614

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

BobdenOs
Copy link
Contributor

This PR adds support for another SQLite driver sql.js is a browser orientated driver which compiles SQLite to wasm.

Enabling the possibility to run cds with @cap-js/sqlite in more environments.

For example better-sqlite3 cannot be loaded into the default npm promoted online environment runkit:
https://runkit.com/bobdenos/cds-test

Error: Could not locate the bindings file. Tried:
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/build/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/build/Release/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/Debug/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/out/Release/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/Release/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/build/default/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/compiled/18.11.0/linux/x64/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/addon-build/release/install-root/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/addon-build/debug/install-root/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/addon-build/default/install-root/better_sqlite3.node
 → /app/available_modules/1713909839000/@cap-js/sqlite/node_modules/better-sqlite3/lib/binding/node-v108-linux-x64/better_sqlite3.node

There are some limitations with sql.js when comparing to better-sqlite3. Which is mostly that it uses more memory and is around 50% slower for running the @cap-js/sqlite tests. Where better-sqlite3 takes ~10 seconds to run all tests. It takes sql.js ~14 seconds, but all current tests are green. Which should be good enough for experimentation scenarios.

sqlite/package.json Outdated Show resolved Hide resolved
Copy link
Member

@patricebender patricebender left a comment

Choose a reason for hiding this comment

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

cool :) Should we run the tests with sql.js as optional tests as part of the PRs? Alternatively we could also run them after merge. What do you think?

@BobdenOs
Copy link
Contributor Author

Verification that the Test WASM job actually uses the fallback driver: log

const init = initSqlJs({})

class WasmSqlite {
constructor(database) {
Copy link
Member

Choose a reason for hiding this comment

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

can we get rid of this warning?

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.

3 participants