-
Notifications
You must be signed in to change notification settings - Fork 543
[wasmJs] Add support for wasmJs to web worker driver #5534
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
[wasmJs] Add support for wasmJs to web worker driver #5534
Conversation
4c15c7c
to
a287e99
Compare
a287e99
to
81a19b8
Compare
@dellisd second one 🙂 |
Hi @IlyaGulya, will your change be available on the SNAPSHOT version after your 3rd pr is merged? |
@deybeer I don't know, I'm external contributor, not a part of SQLDelight team 🙂 |
@IlyaGulya, thanks for the contribution |
@dellisd let us dream with a wasm version on the snapshots 😆 |
Yes, it will be available as SNAPSHOT right after merge. |
@IlyaGulya Little question, after this change, What is the next change about? |
Hi @IlyaGulya Little question, after this change, What is the next change about? |
@deybeer sample web project fixes, and after that maybe small build configuration improvement |
Hi @IlyaGulya, Could you please help me with the documentation to publish your changes on Maven Local? |
@deybeer just clone this branch and call |
@IlyaGulya, is the wasm version only in-memory, or can I configure it to persist to use the persisted data after refreshing the browser? |
@deybeer It's using the same sql.js as current web worker implementation, so yes, it's only in-memory. |
Thank you it's beautiful!! 🥹 🥹 Snapshots
// settings.gradle.kts
pluginManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/edna-aa/sqldelight")
credentials {
username = "<user-name>"
password = "<PAT-with-read-package>"
}
// Restrict this repository to specific versions containing "-wasm"
content {
includeGroup("app.cash.sqldelight") // Restrict to the group
includeVersionByRegex("app.cash.sqldelight", ".*", ".*-wasm.*") // Match any artifact in the group with versions containing "-wasm"
}
}
mavenLocal()
google()
gradlePluginPortal()
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/edna-aa/sqldelight")
credentials {
username = "<user-name>"
password = "<PAT-with-read-package>"
}
// Restrict this repository to specific versions containing "-wasm"
content {
includeGroup("app.cash.sqldelight") // Restrict to the group
includeVersionByRegex("app.cash.sqldelight", ".*", ".*-wasm.*") // Match any artifact in the group with versions containing "-wasm"
}
}
google()
mavenCentral()
mavenLocal()
}
} |
@ahna92 your credentials were sent to everyone who got email notifications, despite you editing them out (and they're still in edit history); make sure to disable those keys and re-generate new ones! And be careful next time :D |
@skaldebane it was on purpose , bc github only allows reading public packages via a pat they got auto revoked by github , guess need to create your own |
@ahna92 Yeah every user has to create their own keys for GitHub Packages, but make sure to never leak your own (even if they're scoped well; they might include future private packages you don't want to be public). |
@skaldebane thank you for your concern, well aware I've created an account just to publish this package, been waiting for 1 year for it ! |
Getting this error when setting generateAsync = true. Any workaround for this? No matching variant of app.cash.sqldelight:async-extensions:2.0.2 was found. The consumer was configured to find a library for use during 'kotlin-runtime', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.js.public.package.json' with value 'public-package-json', attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm', attribute 'org.jetbrains.kotlin.wasm.target' with value 'js' but |
@abhi-rock-pe I had some issues with referencing a package published to local maven with the word SNAPSHOT in the name. I had to change the name of the locally published version to I don't believe you need an explicit |
Pretty strange behavior and I don't know, if I did something wrong: wasm compiles, but I can't access the page. I have set generateAsync to true https://github.com/DrUlysses/Kristine/blob/main/composeApp/build.gradle.kts#L175 There are no errors on build: https://github.com/DrUlysses/Kristine/actions/runs/12612882795/job/35150084827 But on the page https://drulysses.github.io/Kristine/ I got: IllegalStateException: The driver used with SQLDelight is asynchronous, so SQLDelight should be configured for
Kristine-composeApp-wasm-js.uninstantiated.mjs:133:72 Version used is 2.1.0-wasm.2 https://github.com/DrUlysses/Kristine/blob/main/gradle/libs.versions.toml#L18 I have already tried to use different versions, build locally with some tweaks. Don't know, if I am doing something wrong, or it is a bug. There are possibilities to use canvas instead of body, or change sqljs.worker.js (I have used local one, because there ist no sqljs.worker.js for 2.1.0-wasm.2), but I'm not sure, if it will help, or the problem is somewhere else |
Are there people who sucessfully implemented sqldelight for WasmJs ? I'm currently looking at @DrUlysses project to do it but the more resources i have, the more i will understand what i'm doing. 😅 |
hi @JakeWharton original PR before breaking into smaller PRs (jan 2024 😢) We are planning 2025, so appreciate the support 🙏 Tested this on 3 projects working fine so far (with pagination as well) |
I am not involved in the Wasm efforts. Hopefully another maintainer has time to support it fully landing and being released. |
hi @dellisd |
Might I suggest that a worker for a persistent sqlite db is offered as a default, eg
and then include https://github.com/IlyaGulya/TodoAppDecomposeMviKotlin/blob/feature/migrate-to-wasm/web/src/jsMain/resources/sqlite.worker.js by default as well. My hunch is most folks will want to use sqldelight wasm with a persistable db as that is what we are doing with our mobile apps. |
@brendanw sure,I'll take a look on this weekend |
After using the 2.1.0-wasm.2 snapshot library, I encountered this error. FAILURE: Build completed with 12 failures. 1: Task failed with an exception.
|
hey @tangpj Make sure to add maven repo at both pluginManagement & dependencyResolutionManagement and that your personal token has a read package permission |
Hey guys!
After:
|
I managed to make my database work for WasmJs. But is it supposed to work for Js with the same configuration too ?
Edit: i fixed the issue, which was related to the database data. The setup was done properly. Thanks ! |
@bakjoul kotlin/js is officially supported before wasm can check docs from the log shared can't tell much , but i think might due to incompatible make sure to apply this too
|
@dellisd Gentle ping regarding this PR 🙂 |
@dellisd Gentle reminder on this PR Review and approval. |
@IlyaGulya Can you show me a full setup that how can I use yours with wasmJs? I followed to add the wasmJs driver as well, but I don't know what to do after, If I follow the Js setup, it needs to define a If I have a full setup that how can I setup my sqlite database in wasmJs platform that would be great. |
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.
most of this i dont understand but the structure looks good and i will give the people what they want
we're still treating web as experimental in 2.x, so I'm fine with this being a breaking change
Holy cow, thanks! |
Are there any examples yet of how to use this in say Compose for Web setup? |
@joreilly Hi! |
I've also been trying to update PeopleInSpace sample (hacked together in following branch right now https://github.com/joreilly/PeopleInSpace/tree/sql_delight_wasm) but running in to following....is there some additional hook etc needed to ensure tables are created?
|
Ok, turned out I needed to call |
| Package | Type | Package file | Manager | Update | Change | |---|---|---|---|---|---| | [com.github.jsqlparser:jsqlparser](https://github.com/JSQLParser/JSqlParser) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `5.2` -> `5.3` | | [app.cash.sqldelight](https://github.com/sqldelight/sqldelight) | plugin | misk/gradle/libs.versions.toml | gradle | minor | `2.0.2` -> `2.1.0` | | [app.cash.sqldelight:runtime](https://github.com/sqldelight/sqldelight) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `2.0.2` -> `2.1.0` | | [app.cash.sqldelight:mysql-dialect](https://github.com/sqldelight/sqldelight) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `2.0.2` -> `2.1.0` | | [app.cash.sqldelight:jdbc-driver](https://github.com/sqldelight/sqldelight) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `2.0.2` -> `2.1.0` | | [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | | [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.44` -> `2.31.45` | --- ### Release Notes <details> <summary>sqldelight/sqldelight (app.cash.sqldelight)</summary> ### [`v2.1.0`](https://github.com/sqldelight/sqldelight/blob/HEAD/CHANGELOG.md#210---2025-05-16) [Compare Source](sqldelight/sqldelight@2.0.2...2.1.0) ##### Added - \[WASM Driver] Add support for wasmJs to web worker driver ([#​5534](sqldelight/sqldelight#5534) by \[Ilya Gulya]\[IlyaGulya]) - \[PostgreSQL Dialect] Support PostgreSql UnNest Array to rows ([#​5673](sqldelight/sqldelight#5673) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql TSRANGE/TSTZRANGE support ([#​5297](sqldelight/sqldelight#5297) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql Right Full Join ([#​5086](sqldelight/sqldelight#5086) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Postrgesql extract from temporal types ([#​5273](sqldelight/sqldelight#5273) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql array contains operators ([#​4933](sqldelight/sqldelight#4933) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql drop constraint ([#​5288](sqldelight/sqldelight#5288) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Postgresql type casting ([#​5089](sqldelight/sqldelight#5089) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql lateral join operator for subquery ([#​5122](sqldelight/sqldelight#5122) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Postgresql ILIKE operator ([#​5330](sqldelight/sqldelight#5330) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql XML type ([#​5331](sqldelight/sqldelight#5331) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql AT TIME ZONE ([#​5243](sqldelight/sqldelight#5243) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Support postgresql order by nulls ([#​5199](sqldelight/sqldelight#5199) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Add PostgreSQL current date/time function support ([#​5226](sqldelight/sqldelight#5226) by \[Drew Dobson]\[drewd]) - \[PostgreSQL Dialect] PostgreSql Regex operators ([#​5137](sqldelight/sqldelight#5137) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] add brin gist ([#​5059](sqldelight/sqldelight#5059) by \[Griffio]\[griffio]) - \[MySQL Dialect] Support RENAME INDEX for MySql dialect ([#​5212](sqldelight/sqldelight#5212) by \[Oren Kislev]\[orenkislev-faire]) - \[JSON Extension] Add alias to json table function ([#​5372](sqldelight/sqldelight#5372) by \[Griffio]\[griffio]) ##### Changed - \[Compiler] Generated query files return row counts for simple mutators ([#​4578](sqldelight/sqldelight#4578) by \[Marius Volkhart]\[MariusV]) - \[Native Driver] Update NativeSqlDatabase.kt to change readonly flag for DELETE, INSERT, and UPDATE statements ([#​5680](sqldelight/sqldelight#5680) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Change PgInterval to String ([#​5403](sqldelight/sqldelight#5403) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Support SqlDelight modules to implement PostgreSql extensions ([#​5677](sqldelight/sqldelight#5677) by \[Griffio]\[griffio]) ##### Fixed - \[Compiler] fix: notify queries when executing group statements with result ([#​5006](sqldelight/sqldelight#5006) by \[Vitor Hugo Schwaab]\[vitorhugods]) - \[Compiler] Fix SqlDelightModule type resolver ([#​5625](sqldelight/sqldelight#5625) by \[Griffio]\[griffio]) - \[Compiler] Fix 5501 insert object escaped column ([#​5503](sqldelight/sqldelight#5503) by \[Griffio]\[griffio]) - \[Compiler] Compiler: Improve error message such that path links are clickable with the correct line & char position. ([#​5604](sqldelight/sqldelight#5604) by \[Niklas Baudy]\[vanniktech]) - \[Compiler] Fix issue 5298: allow keywords to be used as table names - \[Compiler] fix named executes and add test - \[Compiler] Consider foreign key table constraints when sorting initialization statements ([#​5325](sqldelight/sqldelight#5325) by \[Leon Linhart]\[TheMrMilchmann]) - \[Compiler] Align error underlines properly when tabs are involved ([#​5224](sqldelight/sqldelight#5224) by \[Drew Dobson]\[drewd]) - \[JDBC Driver] Fix memory leak for connectionManager during end of transaction - \[JDBC Driver] Run SQLite migrations inside transaction as mentioned in documentation ([#​5218](sqldelight/sqldelight#5218) by \[Lukáš Moravec]\[morki]) - \[JDBC Driver] Fix leaking connections after transaction commit / rollback ([#​5205](sqldelight/sqldelight#5205) by \[Lukáš Moravec]\[morki]) - \[Gradle Plugin] Execute `DriverInitializer` before `GenerateSchemaTask` ([#​5562](sqldelight/sqldelight#5562) by \[Emeka Nwagu]\[nwagu]) - \[Runtime] Fix crash in LogSqliteDriver when real driver is Async ([#​5723](sqldelight/sqldelight#5723) by \[Eric Denman]\[edenman]) - \[Runtime] Fix StringBuilder capacity ([#​5192](sqldelight/sqldelight#5192) by \[Jan Bína]\[janbina]) - \[PostgreSQL Dialect] PostgreSql create or replace view ([#​5407](sqldelight/sqldelight#5407) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Postgresql to_json ([#​5606](sqldelight/sqldelight#5606) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql numeric resolver ([#​5399](sqldelight/sqldelight#5399) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] sqlite windows function ([#​2799](sqldelight/sqldelight#2799) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql SELECT DISTINCT ON ([#​5345](sqldelight/sqldelight#5345) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] alter table add column if not exists ([#​5309](sqldelight/sqldelight#5309) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] Postgresql async bind parameter ([#​5313](sqldelight/sqldelight#5313) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql boolean literals ([#​5262](sqldelight/sqldelight#5262) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql window functions ([#​5155](sqldelight/sqldelight#5155) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql isNull isNotNull types ([#​5173](sqldelight/sqldelight#5173) by \[Griffio]\[griffio]) - \[PostgreSQL Dialect] PostgreSql select distinct ([#​5172](sqldelight/sqldelight#5172) by \[Griffio]\[griffio]) - \[Paging Extension] paging refresh initial load fix ([#​5615](sqldelight/sqldelight#5615) by \[Eva]\[evant]) - \[Paging Extension] Add MacOS native targets ([#​5324](sqldelight/sqldelight#5324) by \[Vitor Hugo Schwaab]\[vitorhugods]) - \[IntelliJ Plugin] K2 Support </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am every weekday" in timezone Australia/Melbourne, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Never, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). GitOrigin-RevId: 2c67f3c06e13d86329db5149abfceba98e3701a4
Hi, what exactly has to be done to integrate this? The documentation for js (link) seems not applicable. |
This PR adds Kotlin/WasmJS support to the SQLDelight web worker driver
Key Changes
WebWorkerDriver
fromjsMain
tocommonMain
.WebWorkerDriver.sendMessage
toWorkerWrapper
which is implmented by each target.WorkerAction
interface expect/actual because ofwasmJs
bridge limitations (everything passing bridge should extendJsAny
)WorkerAction
companion object to separate objectWorkerActions
createDefaultWebWorkerDriver()
.Technical Limitations
The significant amount of non-shared code between platforms is primarily due to:
org.w3c.dom.Worker
interface in Kotlin Multiplatform