Skip to content

Commit 1927b95

Browse files
Switched to using uuid crate directly
1 parent 94b68ca commit 1927b95

15 files changed

Lines changed: 721 additions & 604 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
- name: Test
168168
run: |
169169
cd extensions/uuid4
170-
wasm-pack test --node
170+
wasm-pack test --chrome --headless
171171
172172
test_sqlite_wasm_uuid7:
173173
strategy:
@@ -181,7 +181,7 @@ jobs:
181181
- name: Test
182182
run: |
183183
cd extensions/uuid7
184-
wasm-pack test --node
184+
wasm-pack test --chrome --headless
185185
186186
187187
test_sqlite_wasm_vfs:

Cargo.toml

Lines changed: 22 additions & 14 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,12 +9,13 @@ 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]
@@ -29,7 +29,7 @@ cc = "1.2.27"
2929
bindgen = { version = "0.72", optional = true }
3030

3131
[dev-dependencies]
32-
wasm-bindgen-test = "0.3.54"
32+
wasm-bindgen-test.workspace = true
3333

3434
[package.metadata.docs.rs]
3535
targets = ["wasm32-unknown-unknown"]
@@ -51,23 +51,31 @@ members = [
5151

5252
[workspace.package]
5353
readme = "README.md"
54+
version = "0.5.2"
5455
edition = "2021"
5556
license = "MIT"
5657
rust-version = "1.82.0"
5758
include = [
58-
'src/**/*.rs',
59-
'build.rs',
60-
'sqlite3/**/*.c',
61-
'sqlite3/**/*.h',
62-
'sqlite3mc/**/*.c',
63-
'sqlite3mc/**/*.h',
64-
'shim/**/*.h',
65-
'shim/**/*.c',
66-
'Cargo.toml',
67-
'/README.md',
68-
'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',
6970
]
7071

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+
7179
[patch.crates-io]
7280
rsqlite-vfs = { path = "./crates/rsqlite-vfs" }
7381
sqlite-wasm-rs = { path = "./" }

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ Contributions are welcome!
9494

9595
## Testing
9696

97-
To run tests for the workspace or specific extensions, use `wasm-pack test --node`.
97+
To run tests for the workspace or specific extensions, use `wasm-pack test --headless --firefox`.
9898

99-
Extensions (like `extensions/uuid4` or `extensions/uuid7`) are configured to run within a NodeJS environment.
99+
Extensions (like `extensions/uuid4` or `extensions/uuid7`) are configured to run within a browser environment.
100100

101101
```bash
102102
# Test uuid4 extension
103103
cd extensions/uuid4
104-
wasm-pack test --node
104+
wasm-pack test --headless --firefox
105105

106106
# Test uuid7 extension
107107
cd extensions/uuid7
108-
wasm-pack test --node
108+
wasm-pack test --headless --firefox
109109
```
110110

111111
## Related Project

examples/nodejs/src/lib.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use std::ffi::CStr;
21
use std::collections::HashSet;
2+
use std::ffi::CStr;
33

44
use sqlite_wasm_rs::{
55
sqlite3, sqlite3_close, sqlite3_column_text, sqlite3_finalize, sqlite3_open_v2,
66
sqlite3_prepare_v3, sqlite3_step, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE,
77
SQLITE_ROW,
88
};
9-
use wasm_bindgen::prelude::wasm_bindgen;
109
use uuid::{Uuid, Version};
10+
use wasm_bindgen::prelude::wasm_bindgen;
1111

1212
#[wasm_bindgen]
1313
extern "C" {
@@ -21,14 +21,7 @@ macro_rules! console_log {
2121

2222
unsafe fn query_uuid(db: *mut sqlite3, sql_stmt: *const std::ffi::c_char) -> String {
2323
let mut stmt = std::ptr::null_mut();
24-
let rc = sqlite3_prepare_v3(
25-
db,
26-
sql_stmt,
27-
-1,
28-
0,
29-
&mut stmt,
30-
std::ptr::null_mut(),
31-
);
24+
let rc = sqlite3_prepare_v3(db, sql_stmt, -1, 0, &mut stmt, std::ptr::null_mut());
3225
assert_eq!(SQLITE_OK, rc, "Failed to prepare statement");
3326

3427
let mut res = String::new();
@@ -76,7 +69,7 @@ async fn main() {
7669
console_log!("Generating 1000 UUIDv4...");
7770
let mut v4_results = Vec::with_capacity(1000);
7871
let sql = c"SELECT uuid();";
79-
72+
8073
for _ in 0..1000 {
8174
v4_results.push(query_uuid(db, sql.as_ptr()));
8275
}
@@ -88,8 +81,15 @@ async fn main() {
8881

8982
// Check version & parsing
9083
for (i, s) in v4_results.iter().enumerate() {
91-
let u = Uuid::parse_str(s).unwrap_or_else(|e| panic!("Failed to parse UUIDv4 at index {}: {} - {}", i, s, e));
92-
assert_eq!(u.get_version(), Some(Version::Random), "UUID at index {} is not v4: {}", i, s);
84+
let u = Uuid::parse_str(s)
85+
.unwrap_or_else(|e| panic!("Failed to parse UUIDv4 at index {}: {} - {}", i, s, e));
86+
assert_eq!(
87+
u.get_version(),
88+
Some(Version::Random),
89+
"UUID at index {} is not v4: {}",
90+
i,
91+
s
92+
);
9393
}
9494
console_log!("Version check passed for UUIDv4");
9595

@@ -102,52 +102,64 @@ async fn main() {
102102
v7_results.push(query_uuid(db, sql.as_ptr()));
103103
}
104104

105-
// Check uniqueness
105+
// Check uniqueness
106106
let set: HashSet<_> = v7_results.iter().cloned().collect();
107107
assert_eq!(set.len(), 1000, "All UUIDv7 must be unique");
108108
console_log!("Unique check passed for UUIDv7");
109109

110110
// Check sorting (Monotonicity)
111111
// Since UUIDv7 is time-ordered, later generations should generally be greater than previous ones.
112112
// However, if generated in the same millisecond, the random component decides order.
113-
// Strict monotonicity isn't guaranteed across all implementations unless they share state,
113+
// Strict monotonicity isn't guaranteed across all implementations unless they share state,
114114
// but uuid::Uuid::now_v7() generally attempts internally to be monotonic if called rapidly.
115115
// Wait, the Rust `uuid` crate documentation says `now_v7` guarantees monotonicity for same-process calls if the feature is enabled?
116116
// Actually `Uuid::now_v7()` uses `context::Context` thread-locally if available, or just random.
117117
// The implementation in extensions/uuid7 uses `Uuid::now_v7()`.
118118
// Let's check if the list is sorted.
119-
119+
120120
let mut sorted_v7 = v7_results.clone();
121121
sorted_v7.sort();
122-
122+
123123
// This assertion might be flaky if the clock goes backwards or multiple threads (not in WASM mostly).
124124
// But for a single thread tight loop, it should be strictly monotonic or at least non-decreasing.
125125
// Since we assert uniqueness, non-decreasing + unique = strictly increasing.
126-
126+
127127
if v7_results != sorted_v7 {
128-
console_log!("Warning: UUIDv7 results were not strictly monotonic.");
129-
// Find first violation
130-
for i in 0..999 {
131-
if v7_results[i] > v7_results[i+1] {
132-
console_log!("Violation at index {}: {} > {}", i, v7_results[i], v7_results[i+1]);
133-
// Allow slight harmless reordering if any, but UUIDv7 SHOULD be monotonic.
134-
// The user asked to "check they are unique and sorted".
135-
// So I will assert it.
136-
}
137-
}
138-
panic!("UUIDv7 results are not sorted!");
128+
console_log!("Warning: UUIDv7 results were not strictly monotonic.");
129+
// Find first violation
130+
for i in 0..999 {
131+
if v7_results[i] > v7_results[i + 1] {
132+
console_log!(
133+
"Violation at index {}: {} > {}",
134+
i,
135+
v7_results[i],
136+
v7_results[i + 1]
137+
);
138+
// Allow slight harmless reordering if any, but UUIDv7 SHOULD be monotonic.
139+
// The user asked to "check they are unique and sorted".
140+
// So I will assert it.
141+
}
142+
}
143+
panic!("UUIDv7 results are not sorted!");
139144
}
140145
console_log!("Sort order check passed for UUIDv7");
141146

142147
// Check version
143148
for (i, s) in v7_results.iter().enumerate() {
144-
let u = Uuid::parse_str(s).unwrap_or_else(|e| panic!("Failed to parse UUIDv7 at index {}: {} - {}", i, s, e));
145-
assert_eq!(u.get_version(), Some(Version::SortRand), "UUID at index {} is not v7: {}", i, s);
149+
let u = Uuid::parse_str(s)
150+
.unwrap_or_else(|e| panic!("Failed to parse UUIDv7 at index {}: {} - {}", i, s, e));
151+
assert_eq!(
152+
u.get_version(),
153+
Some(Version::SortRand),
154+
"UUID at index {} is not v7: {}",
155+
i,
156+
s
157+
);
146158
}
147159
console_log!("Version check passed for UUIDv7");
148-
160+
149161
sqlite3_close(db);
150162
}
151-
163+
152164
console_log!("All tests passed!");
153165
}

extensions/sqlite-vec/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ keywords = ["sqlite", "sqlite-wasm", "wasm", "webassembly", "sqlite-vec"]
1717
cc = "1.2.44"
1818

1919
[dev-dependencies]
20-
wasm-bindgen-test = "0.3.55"
21-
rusqlite = "0.38.0"
20+
wasm-bindgen-test.workspace = true
21+
rusqlite.workspace = true
2222

2323
[package.metadata.docs.rs]
2424
targets = ["wasm32-unknown-unknown"]

extensions/uuid4/Cargo.toml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
[package]
22
name = "sqlite-wasm-uuid4"
3-
version = "0.1.0"
4-
edition = "2021"
53
authors = ["Spxg <unsafe@outlook.es>"]
6-
readme = "README.md"
7-
license = "MIT"
84
description = "`wasm32-unknown-unknown` bindings to the `uuid4` extension."
95
categories = ["development-tools::ffi", "wasm", "database"]
106
keywords = ["sqlite", "sqlite-wasm", "wasm", "webassembly", "uuid4"]
7+
version.workspace = true
8+
readme.workspace = true
9+
edition.workspace = true
10+
license.workspace = true
1111

1212
[dependencies]
13-
uuid = { version = "1.20.0", features = ["v4", "v7", "js", "macro-diagnostics"] }
14-
getrandom = { version = "0.2", features = ["js"] }
15-
wasm-bindgen = "0.2.104"
16-
sqlite-wasm-rs = { path = "../../" }
13+
uuid.workspace = true
14+
wasm-bindgen.workspace = true
15+
sqlite-wasm-rs.workspace = true
1716

1817
[dev-dependencies]
19-
wasm-bindgen-test = "0.3.55"
20-
sqlite-wasm-rs = { path = "../../" }
21-
js-sys = "0.3.81"
22-
rusqlite = "0.38.0"
18+
wasm-bindgen-test.workspace = true
19+
rusqlite.workspace = true
2320

2421
[package.metadata.docs.rs]
2522
targets = ["wasm32-unknown-unknown"]

extensions/uuid4/README.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

extensions/uuid4/build.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)