Skip to content

feat: support for node:sqlite and sql.js#614

Merged
BobdenOs merged 30 commits intomainfrom
sqlite/wasm
Mar 3, 2026
Merged

feat: support for node:sqlite and sql.js#614
BobdenOs merged 30 commits intomainfrom
sqlite/wasm

Conversation

@BobdenOs
Copy link
Copy Markdown
Contributor

@BobdenOs BobdenOs commented Apr 23, 2024

This PR adds support for node-sqlite and sql.js (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.

Comment thread sqlite/package.json
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread sqlite/lib/sql.js.js Outdated
const init = initSqlJs({})

class WasmSqlite {
constructor(database) {
Copy link
Copy Markdown
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?

@petermuessig
Copy link
Copy Markdown

@BobdenOs @danjoa @patricebender are there any further interests on your side to enable this feature for the @cap-js/sqlite package? This feature would be quite interesting - maybe even as a standalone @cap-js/sql.js package to allow to run CAP in a webcontainer. SQLite doesn't work here as it requires native bindings and with sql.js we could run it inside a webcontainer. Or do you have anything available here - if yes, I would be highly interested in this for the UI5 tutorials to run against a webcontainer based environment in the browser. THX!

Comment thread .github/workflows/sqlite-wasm.yml Fixed
@BobdenOs
Copy link
Copy Markdown
Contributor Author

@petermuessig the current state should be up-to-date again.

Currently the only blocker is that the sql.js compilation flags doesn't include the native math functions (test, PR).

@petermuessig
Copy link
Copy Markdown

@BobdenOs thanks for the information. As said in our chat, I'll verify the workaround you provided for me so far to check whether I can run UI5 applications against the CDS server running on sql.js in the web container. I will let you know whether all works fine... BIG THX again!

Comment thread sqlite/lib/SQLiteService.js Outdated
dbc.function('minute', deterministic, d => d === null ? null : toDate(d, true).getUTCMinutes())
dbc.function('second', deterministic, d => d === null ? null : toDate(d, true).getUTCSeconds())
if (!dbc.memory) dbc.pragma('journal_mode = WAL')
if (!dbc.memory) dbc.pragma?.('journal_mode = WAL')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!dbc.memory) dbc.pragma?.('journal_mode = WAL')
if (!dbc.memory) dbc.pragma?.('journal_mode = WAL') || dbc.exec('PRAGMA journal_mode = WAL')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The node:sqlite doesn't have a memory property. So the check also has to be extended.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dbc.memory??=database === ':memory:'?

Comment thread sqlite/lib/SQLiteService.js Outdated
@johannes-vogel johannes-vogel changed the title feat: Add sql.js fallback for sqlite in wasm feat: Add support for node:sqlite and sql.js Feb 27, 2026
@johannes-vogel johannes-vogel changed the title feat: Add support for node:sqlite and sql.js feat: support for node:sqlite and sql.js Feb 27, 2026
Copy link
Copy Markdown
Contributor

@johannes-vogel johannes-vogel left a comment

Choose a reason for hiding this comment

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

lgtm

Comment thread .github/workflows/test.yml Outdated
Comment thread .github/workflows/test.yml Outdated
Comment thread .github/workflows/test.yml Outdated
@johannes-vogel
Copy link
Copy Markdown
Contributor

@BobdenOs merge?

@BobdenOs BobdenOs merged commit 887d1bb into main Mar 3, 2026
5 checks passed
@BobdenOs BobdenOs deleted the sqlite/wasm branch March 3, 2026 08:26
@cap-bots cap-bots mentioned this pull request Mar 2, 2026
sjvans added a commit that referenced this pull request Mar 9, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>db-service: 2.9.0</summary>

##
[2.9.0](db-service-v2.8.2...db-service-v2.9.0)
(2026-03-09)


### Added

* runtime views ([#1410](#1410))
([5242675](5242675))
* support calculated elements in hierarchies
([#1456](#1456))
([97c6f66](97c6f66))


### Fixed

* **`exists`:** detect join relevant path after exists
([#1412](#1412))
([c5bad06](c5bad06)),
closes [#1407](#1407)
* **cqn2sql:** Relied on inconstistent behavior of cds.ql.cloned queries
([#1500](#1500))
([f9cb201](f9cb201))
* enable expressions for `inline`
([#1512](#1512))
([65f78e1](65f78e1))
* path expressions for scoped queries
([#1507](#1507))
([0f1e234](0f1e234))
* reject duplicated wildcards
([#1511](#1511))
([b483062](b483062))
* the combination of `iterator` and `SELECT.one`
([#1514](#1514))
([4b28579](4b28579))
* wildcard on inlined assoc
([#1513](#1513))
([e520b97](e520b97))
</details>

<details><summary>hana: 2.7.0</summary>

##
[2.7.0](hana-v2.6.0...hana-v2.7.0)
(2026-03-09)


### Added

* runtime views ([#1410](#1410))
([5242675](5242675))


### Fixed

* avoid rollback race condition during .disconnect
([#1502](#1502))
([4fa5758](4fa5758))
* hana groupby with path expressions
([#1493](#1493))
([920acde](920acde))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @cap-js/db-service bumped from ^2.8.2 to ^2.9.0
</details>

<details><summary>postgres: 2.2.0</summary>

##
[2.2.0](postgres-v2.1.3...postgres-v2.2.0)
(2026-03-09)


### Added

* support for `node:sqlite` and `sql.js`
([#614](#614))
([887d1bb](887d1bb))


### Fixed

* hana groupby with path expressions
([#1493](#1493))
([920acde](920acde))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @cap-js/db-service bumped from ^2.8.2 to ^2.9.0
</details>

<details><summary>sqlite: 2.2.0</summary>

##
[2.2.0](sqlite-v2.1.3...sqlite-v2.2.0)
(2026-03-09)


### Added

* support for `node:sqlite` and `sql.js`
([#614](#614))
([887d1bb](887d1bb))


### Fixed

* hana groupby with path expressions
([#1493](#1493))
([920acde](920acde))
* the combination of `iterator` and `SELECT.one`
([#1514](#1514))
([4b28579](4b28579))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @cap-js/db-service bumped from ^2.8.2 to ^2.9.0
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: sjvans <30337871+sjvans@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.

7 participants