Skip to content

Commit 939d488

Browse files
Merge pull request #1 from LucaCappelletti94/extension-uuid-crate
Moving uuid crate based version
2 parents 0669cfd + 1927b95 commit 939d488

21 files changed

Lines changed: 1086 additions & 689 deletions

File tree

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,35 @@ jobs:
155155
cd extensions/sqlite-vec
156156
wasm-pack test --node
157157
158+
test_sqlite_wasm_uuid4:
159+
strategy:
160+
matrix:
161+
os: [ubuntu-latest]
162+
runs-on: ${{ matrix.os }}
163+
steps:
164+
- uses: actions/checkout@v4
165+
- name: Install wasm-pack
166+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
167+
- name: Test
168+
run: |
169+
cd extensions/uuid4
170+
wasm-pack test --chrome --headless
171+
172+
test_sqlite_wasm_uuid7:
173+
strategy:
174+
matrix:
175+
os: [ubuntu-latest]
176+
runs-on: ${{ matrix.os }}
177+
steps:
178+
- uses: actions/checkout@v4
179+
- name: Install wasm-pack
180+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
181+
- name: Test
182+
run: |
183+
cd extensions/uuid7
184+
wasm-pack test --chrome --headless
185+
186+
158187
test_sqlite_wasm_vfs:
159188
strategy:
160189
matrix:

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
3-
"rust-analyzer.cargo.features": ["bindgen"]
3+
"rust-analyzer.cargo.features": [
4+
"bindgen"
5+
],
6+
"chat.tools.terminal.autoApprove": {
7+
"wasm-pack": true
8+
}
49
}

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
### Added
77

8-
* Added support for the SQLite `uuid4` extension, enabled via the `uuid4` feature flag.
9-
* Added support for the Postgres18 `uuid7` extension, enabled via the `uuid7` feature flag, ported from PostgreSQL implementation.
8+
* Integrated the [`uuid`](https://docs.rs/uuid/latest/uuid/) rust crate to provide functionality to generate UUIDs in the `uuid4` and `uuid7` extensions inside SQLite.
109

1110
### Fixed
1211

Cargo.toml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "sqlite-wasm-rs"
33
links = "wsqlite3"
4-
version = "0.5.2"
54
authors = ["Spxg <unsafe@outlook.es>"]
65
repository = "https://github.com/Spxg/sqlite-wasm-rs"
76
description = "`wasm32-unknown-unknown` bindings to the libsqlite3 library."
@@ -10,29 +9,27 @@ keywords = ["sqlite", "sqlite-wasm", "wasm", "webassembly", "javascript"]
109
readme.workspace = true
1110
edition.workspace = true
1211
license.workspace = true
12+
version.workspace = true
1313
rust-version.workspace = true
1414
include.workspace = true
1515

1616
[dependencies]
1717
rsqlite-vfs = "0.1.0"
18-
wasm-bindgen = { version = "0.2.104", default-features = false }
18+
wasm-bindgen.workspace = true
1919
js-sys = { version = "0.3.81", default-features = false }
2020

2121
[features]
2222
# SQLite3MultipleCiphers
2323
# <https://github.com/utelle/SQLite3MultipleCiphers>
2424
# <https://utelle.github.io/SQLite3MultipleCiphers>
2525
sqlite3mc = []
26-
# Link the uuid extension to the library.
27-
uuid4 = []
28-
uuid7 = []
2926

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

3431
[dev-dependencies]
35-
wasm-bindgen-test = "0.3.54"
32+
wasm-bindgen-test.workspace = true
3633

3734
[package.metadata.docs.rs]
3835
targets = ["wasm32-unknown-unknown"]
@@ -45,30 +42,40 @@ members = [
4542
"crates/sqlite-wasm-libc",
4643
"crates/sqlite-wasm-vfs",
4744
"extensions/sqlite-vec",
45+
"extensions/uuid4",
46+
"extensions/uuid7",
4847
"examples/implement-a-vfs",
4948
"examples/nodejs",
5049
"examples/use-prebuild-lib",
5150
]
5251

5352
[workspace.package]
5453
readme = "README.md"
54+
version = "0.5.2"
5555
edition = "2021"
5656
license = "MIT"
5757
rust-version = "1.82.0"
5858
include = [
59-
'src/**/*.rs',
60-
'build.rs',
61-
'sqlite3/**/*.c',
62-
'sqlite3/**/*.h',
63-
'sqlite3mc/**/*.c',
64-
'sqlite3mc/**/*.h',
65-
'shim/**/*.h',
66-
'shim/**/*.c',
67-
'Cargo.toml',
68-
'/README.md',
69-
'LICENSE',
59+
'src/**/*.rs',
60+
'build.rs',
61+
'sqlite3/**/*.c',
62+
'sqlite3/**/*.h',
63+
'sqlite3mc/**/*.c',
64+
'sqlite3mc/**/*.h',
65+
'shim/**/*.h',
66+
'shim/**/*.c',
67+
'Cargo.toml',
68+
'/README.md',
69+
'LICENSE',
7070
]
7171

72+
[workspace.dependencies]
73+
sqlite-wasm-rs = { path = "./", version = "0.5.2" }
74+
wasm-bindgen = { version = "0.2.104", default-features = false }
75+
wasm-bindgen-test = "0.3.54"
76+
rusqlite = "0.38.0"
77+
uuid = { version = "1.20.0", features = ["v4", "v7", "js"] }
78+
7279
[patch.crates-io]
7380
rsqlite-vfs = { path = "./crates/rsqlite-vfs" }
7481
sqlite-wasm-rs = { path = "./" }

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ See [ADDING_EXTENSIONS.md](docs/ADDING_EXTENSIONS.md) for instructions on how to
9292

9393
Contributions are welcome!
9494

95+
## Testing
96+
97+
To run tests for the workspace or specific extensions, use `wasm-pack test --headless --firefox`.
98+
99+
Extensions (like `extensions/uuid4` or `extensions/uuid7`) are configured to run within a browser environment.
100+
101+
```bash
102+
# Test uuid4 extension
103+
cd extensions/uuid4
104+
wasm-pack test --headless --firefox
105+
106+
# Test uuid7 extension
107+
cd extensions/uuid7
108+
wasm-pack test --headless --firefox
109+
```
110+
95111
## Related Project
96112

97113
* [`diesel`](https://github.com/diesel-rs/diesel): A safe, extensible ORM and Query Builder for Rust.

build.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ fn bindgen(output: &std::path::PathBuf) {
189189
bindings.write_to_file(output).unwrap();
190190
}
191191

192-
#[allow(clippy::vec_init_then_push)]
193192
fn compile() {
194193
const C_SOURCE: [&str; 36] = [
195194
// string
@@ -258,23 +257,5 @@ fn compile() {
258257
#[cfg(feature = "sqlite3mc")]
259258
cc.flags(SQLITE3_MC_FEATURED);
260259

261-
// Extensions
262-
// Define a list of extensions with their feature flag and source file.
263-
// (feature_name, source_file)
264-
#[allow(unused_mut)]
265-
let mut extensions: Vec<(&str, &str)> = Vec::new();
266-
267-
#[cfg(feature = "uuid4")]
268-
extensions.push(("uuid4", "sqlite3/ext/uuid4.c"));
269-
270-
#[cfg(feature = "uuid7")]
271-
extensions.push(("uuid7", "sqlite3/ext/uuid7.c"));
272-
273-
for (_feature, source) in &extensions {
274-
cc.file(source);
275-
// Ensure extensions can find sqlite3ext.h
276-
cc.include("sqlite3");
277-
}
278-
279260
cc.compile("wsqlite3");
280261
}

examples/nodejs/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ edition = "2021"
66
[dependencies]
77
wasm-bindgen = "0.2.104"
88
sqlite-wasm-rs = { path = "../.." }
9+
sqlite-wasm-uuid4 = { path = "../../extensions/uuid4" }
10+
sqlite-wasm-uuid7 = { path = "../../extensions/uuid7" }
911
wasm-bindgen-futures = "0.4.54"
12+
uuid = { version = "1.20.0", features = ["js"] }
13+
getrandom = { version = "0.2", features = ["js"] }
14+
console_error_panic_hook = "0.1.7"
1015

1116
[lib]
12-
crate-type = ["cdylib"]
17+
crate-type = ["cdylib", "rlib"]

examples/nodejs/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if (!globalThis.crypto) {
2+
globalThis.crypto = require("node:crypto").webcrypto;
3+
}
4+
5+
const wasm = require('./pkg/nodejs.js');
6+
// wasm.main(); // main is executed automatically due to #[wasm_bindgen(start)]

0 commit comments

Comments
 (0)