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
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,17 @@ jobs:
- name: Install wasm-pack
run: cargo install wasm-pack

- name: Install emscripten toolchains
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest

- name: Test unit and integration tests
run: cargo xtask run-tests --wasm sqlite
run: |
source ./emsdk/emsdk_env.sh
cargo xtask run-tests --wasm sqlite

sqlite_bundled:
name: Check sqlite bundled + Sqlite with asan
Expand Down
5 changes: 3 additions & 2 deletions diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ path = "../diesel_derives"
libsqlite3-sys = { version = ">=0.17.2, <0.32.0", optional = true, features = ["bundled_bindings"] }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
sqlite-wasm-rs = { version = ">=0.1.3, <0.2.0", optional = true }
sqlite-wasm-rs = { version = ">=0.3.0, <0.4.0", optional = true, default-features = false }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
# Something is dependent on it, so we use feature to override it.
# Something is dependent on it, we use feature to override it.
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen-test = "0.3.49"
sqlite-wasm-rs = { version = ">=0.3.0, <0.4.0", default-features = false, features = ["bundled"] }

[dev-dependencies]
cfg-if = "1"
Expand Down
6 changes: 0 additions & 6 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,6 @@ pub mod prelude {
#[cfg(feature = "sqlite")]
#[doc(inline)]
pub use crate::sqlite::SqliteConnection;

// These exported API from `sqlite-wasm-rs` are stable:
#[cfg(feature = "sqlite")]
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
#[doc(inline)]
pub use sqlite_wasm_rs::export::init_sqlite;
}

#[doc(inline)]
Expand Down
27 changes: 8 additions & 19 deletions diesel/src/sqlite/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,9 @@ impl Connection for SqliteConnection {
/// If you plan to use this connection type on the `wasm32-unknown-unknown` target please
/// make sure to read the following notes:
///
/// * You must initialize sqlite using `diesel::init_sqlite` before calling `SqliteConnection::establish`.
/// * The database is stored in memory by default. sqlite-wasm
/// provides different persistent VFS (Virtual File Systems), but they all have different limitations.
/// See <https://sqlite.org/wasm/doc/trunk/persistence.md> for details. Make sure to chose
/// an appropriated VFS implementation for your usecase.
/// * VFS can be selected through the `database_url` via an URL option, such as `file:data.db?vfs=opfs`.
/// * The database is stored in memory by default.
/// * Persistent VFS (Virtual File Systems) is optional,
/// see <https://github.com/Spxg/sqlite-wasm-rs/blob/master/VFS.md> for details
fn establish(database_url: &str) -> ConnectionResult<Self> {
let mut instrumentation = DynInstrumentation::default_instrumentation();
instrumentation.on_connection_event(InstrumentationEvent::StartEstablishConnection {
Expand Down Expand Up @@ -983,26 +980,18 @@ mod tests {

#[cfg(all(target_family = "wasm", target_os = "unknown"))]
#[wasm_bindgen_test::wasm_bindgen_test]
async fn test_sqlite_wasm_vfs_default() {
crate::init_sqlite().await.unwrap();
fn test_sqlite_wasm_vfs_default() {
SqliteConnection::establish("test_sqlite_wasm_vfs_default.db").unwrap();
}

#[cfg(all(target_family = "wasm", target_os = "unknown"))]
#[wasm_bindgen_test::wasm_bindgen_test]
async fn test_sqlite_wasm_vfs_opfs() {
crate::init_sqlite().await.unwrap();
SqliteConnection::establish("file:test_sqlite_wasm_vfs_opfs.db?vfs=opfs").unwrap();
}

#[cfg(all(target_family = "wasm", target_os = "unknown"))]
#[wasm_bindgen_test::wasm_bindgen_test]
async fn test_sqlite_wasm_vfs_opfs_sahpool() {
let sqlite = crate::init_sqlite().await.unwrap();
let util = sqlite.install_opfs_sahpool(None).await.unwrap();
let util = sqlite_wasm_rs::export::install_opfs_sahpool(None, false)
.await
.unwrap();
SqliteConnection::establish("file:test_sqlite_wasm_vfs_opfs_sahpool.db?vfs=opfs-sahpool")
.unwrap();
assert_eq!(1, util.get_file_count());
util.remove_vfs().await;
assert!(util.get_file_count() > 0);
}
}
Loading
Loading