Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.'cfg(target_arch = "wasm32")']
runner = 'wasm-bindgen-test-runner'
8 changes: 2 additions & 6 deletions .github/workflows/precompile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Precompile library
- name: Setup emscripten
uses: ./.github/actions/setup-emscripten
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ../sqlite-wasm-rs
rustup toolchain install 1.78.0
rustup default 1.78.0
rustup target add wasm32-unknown-unknown
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
uses: ./.github/actions/setup-emscripten
- name: Test bundled
run: |
cd sqlite-wasm-rs
wasm-pack test --chrome --headless --features relaxed-idb
- name: Test custom-libc
if: matrix.os != 'windows-latest'
Expand All @@ -41,7 +40,6 @@ jobs:
uses: ./.github/actions/setup-emscripten
- name: Test bundled sqlite3mc
run: |
cd sqlite-wasm-rs
wasm-pack test --chrome --headless --features relaxed-idb,sqlite3mc

test_diesel:
Expand All @@ -57,7 +55,7 @@ jobs:
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
printf "[patch.crates-io]\n" >> Cargo.toml
printf "sqlite-wasm-rs = { path = \"../sqlite-wasm-rs\" }\n" >> Cargo.toml
printf "sqlite-wasm-rs = { path = \"..\" }\n" >> Cargo.toml
WASM_BINDGEN_TEST_TIMEOUT=120 cargo xtask run-tests --wasm sqlite

test_rusqlite:
Expand All @@ -73,7 +71,7 @@ jobs:
git clone https://github.com/Spxg/rusqlite.git
cd rusqlite
printf "[patch.crates-io]\n" >> Cargo.toml
printf "sqlite-wasm-rs = { path = \"../sqlite-wasm-rs\" }\n" >> Cargo.toml
printf "sqlite-wasm-rs = { path = \"..\" }\n" >> Cargo.toml
WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --chrome --headless --features modern-base

test_clippy:
Expand All @@ -82,7 +80,6 @@ jobs:
- uses: actions/checkout@v4
- name: Check clippy
run: |
cd sqlite-wasm-rs
cargo clippy --no-default-features --features precompiled,relaxed-idb -- -D warnings

test_implement_a_vfs:
Expand Down Expand Up @@ -116,7 +113,6 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Test
run: |
cd sqlite-wasm-rs
wasm-pack test --chrome --headless --no-default-features --features precompiled,relaxed-idb

test_atomics:
Expand All @@ -132,7 +128,6 @@ jobs:
uses: ./.github/actions/setup-emscripten
- name: Test
run: |
cd sqlite-wasm-rs
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' rustup run nightly wasm-pack test --chrome --headless --features relaxed-idb -Z build-std=panic_abort,std
Expand All @@ -152,7 +147,6 @@ jobs:
version: '3.1.52'
- name: Test MSRV
run: |
cd sqlite-wasm-rs
rustup toolchain install 1.78.0
rustup default 1.78.0
wasm-pack test --chrome --headless --features relaxed-idb
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": ["relaxed-idb"]
}
67 changes: 63 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,69 @@
[package]
name = "sqlite-wasm-rs"
version = "0.4.4"
edition = "2021"
authors = ["Spxg <[email protected]>"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/Spxg/sqlite-wasm-rs"
description = "Provide sqlite solution for wasm32-unknown-unknown target."
categories = ["development-tools::ffi", "wasm", "database"]
keywords = ["sqlite", "sqlite-wasm", "wasm", "webassembly", "javascript"]
rust-version = "1.78.0"

[dependencies]
once_cell = "1.21.3"
tokio = { version = "1.45.1", features = ["sync"] }
thiserror = "2.0.12"

wasm-bindgen = "0.2.104"
wasm-bindgen-futures = "0.4.54"
js-sys = "0.3.81"
web-sys = { version = "0.3.81", features = [
"StorageManager",
"FileSystemSyncAccessHandle",
"FileSystemDirectoryHandle",
"FileSystemGetDirectoryOptions",
"FileSystemReadWriteOptions",
"WorkerGlobalScope",
"WorkerNavigator",
"FileSystemGetFileOptions",
"FileSystemFileHandle",
]}

indexed_db_futures = { version = "0.6.4", optional = true }
sqlite-wasm-libc = { path = "crates/sqlite-wasm-libc", version = "0.1.0", optional = true }

[features]
default = ["bundled"]
bundled = ["cc"]
precompiled = []
buildtime-bindgen = ["bindgen"]
custom-libc = ["bundled", "sqlite-wasm-libc"]
# SQLite3MultipleCiphers
# <https://github.com/utelle/SQLite3MultipleCiphers>
# <https://utelle.github.io/SQLite3MultipleCiphers>
sqlite3mc = ["bundled"]
relaxed-idb = ["indexed_db_futures"]

[dev-dependencies]
wasm-bindgen-test = "0.3.54"
web-time = "1.1.0"

[build-dependencies]
bindgen = { version = "0.72", optional = true }
cc = { version = "1.2.27", optional = true }

[package.metadata.docs.rs]
no-default-features = true
features = ["precompiled"]
targets = ["wasm32-unknown-unknown"]

[workspace]
resolver = "2"
exclude = ["examples/custom-libc"]
members = [
"sqlite-wasm-rs",
"sqlite-wasm-libc",

"examples/custom-libc",
"crates/sqlite-wasm-libc",
"examples/implement-a-vfs",
"examples/nodejs"
]
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,25 @@ async fn open_db() {

The following vfs have been implemented:

* [`memory`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-rs/src/vfs/memory.rs): as the default vfs, no additional conditions are required, store the database in memory.
* [`sahpool`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-rs/src/vfs/sahpool.rs): ported from sqlite-wasm, store the database in opfs.
* [`relaxed-idb`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-rs/src/vfs/relaxed_idb.rs): store the database in blocks in indexed db.
* [`memory`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/src/vfs/memory.rs): as the default vfs, no additional conditions are required, store the database in memory.
* [`sahpool`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/src/vfs/sahpool.rs): ported from sqlite-wasm, store the database in opfs.
* [`relaxed-idb`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/src/vfs/relaxed_idb.rs): store the database in blocks in indexed db.

Go to [`here`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-rs/src/vfs/README.md) to check it out.
### VFS Comparison

||MemoryVFS|SyncAccessHandlePoolVFS|RelaxedIdbVFS|
|-|-|-|-|
|Storage|RAM|OPFS|IndexedDB|
|Contexts|All|Dedicated Worker|All|
|Multiple connections|:x:|:x:|:x:|
|Full durability|✅|✅|:x:|
|Relaxed durability|:x:|:x:|✅|
|Multi-database transactions|✅|✅|✅|
|No COOP/COEP requirements|✅|✅|✅|

### How to implement a VFS

Here is an example showing how to use `sqlite-wasm-rs` to implement a simple in-memory VFS, see [`implement-a-vfs`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/examples/implement-a-vfs) example.

## About multithreading

Expand All @@ -96,7 +110,7 @@ About security:

We provide the ability to customize "libc", cargo provides a [`links`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-links-field) field that can be used to specify which library to link to.

We created a new [`sqlite-wasm-libc`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-libc) library with no implementation and only a `links = "libc"` configuration, and then with the help of [overriding build scripts](https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts), you can overriding its configuration in your crate and link sqlite to your custom libc.
We created a new [`sqlite-wasm-libc`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/crates/sqlite-wasm-libc) library with no implementation and only a `links = "libc"` configuration, and then with the help of [overriding build scripts](https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts), you can overriding its configuration in your crate and link sqlite to your custom libc.

More see [`custom-libc`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/examples/custom-libc) example.

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions crates/sqlite-wasm-libc/LICENSE
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/custom-libc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
sqlite-wasm-rs = { path = "../../sqlite-wasm-rs", features = ["custom-libc"] }
sqlite-wasm-rs = { path = "../..", features = ["custom-libc"] }

js-sys = "0.3.77"
wasm-bindgen = "0.2.100"
Expand Down
2 changes: 1 addition & 1 deletion examples/implement-a-vfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
sqlite-wasm-rs = { path = "../../sqlite-wasm-rs" }
sqlite-wasm-rs = { path = "../.." }
wasm-bindgen-test = "0.3.50"

2 changes: 1 addition & 1 deletion examples/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
wasm-bindgen = "0.2.104"
sqlite-wasm-rs = { path = "../../sqlite-wasm-rs" }
sqlite-wasm-rs = { path = "../.." }
wasm-bindgen-futures = "0.4.54"

[lib]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion sqlite-wasm-libc/LICENSE

This file was deleted.

60 changes: 0 additions & 60 deletions sqlite-wasm-rs/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion sqlite-wasm-rs/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion sqlite-wasm-rs/README.md

This file was deleted.

Loading
Loading