-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
5,049 additions
and
84 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "bitwarden-db-tests" | ||
version = "0.1.0" | ||
publish = false | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
|
||
[[bin]] | ||
name = "bitwarden_db_tests" | ||
path = "bin/main.rs" | ||
|
||
[lib] | ||
name = "bitwarden_db_tests" | ||
crate-type = ["cdylib", "lib"] | ||
|
||
[dependencies] | ||
bitwarden-db = { workspace = true } | ||
tokio = { version = "1.36.0", features = ["rt", "macros"] } | ||
wasm-bindgen = "0.2.92" | ||
wasm-bindgen-futures = "0.4.41" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use bitwarden_db_tests::run_tests; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
run_tests().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { runTests } from "./pkg"; | ||
|
||
import * as SQLite from "wa-sqlite"; | ||
import SQLiteESMFactory from "wa-sqlite/dist/wa-sqlite-async.mjs"; | ||
import { IDBMirrorVFS } from "wa-sqlite/src/examples/IDBMirrorVFS"; | ||
import { IDBBatchAtomicVFS } from "wa-sqlite/src/examples/IDBBatchAtomicVFS"; | ||
|
||
const sqliteModule = await SQLiteESMFactory(); | ||
const sqlite3 = SQLite.Factory(sqliteModule); | ||
|
||
// Register a custom file system. | ||
// const vfs = await IDBBatchAtomicVFS.create("hello", sqliteModule); | ||
// const vfs = await IDBMirrorVFS.create("hello", sqliteModule); | ||
// sqlite3.vfs_register(vfs, true); | ||
|
||
class SqliteDatabase { | ||
constructor(db) { | ||
this.db = db; | ||
} | ||
|
||
static async factory(name) { | ||
console.debug("OPENED DATABASE: ", name); | ||
|
||
// Open the database. | ||
const db = await sqlite3.open_v2(name); | ||
|
||
window.sqlite = sqlite3; | ||
window.test = db; | ||
|
||
return new SqliteDatabase(db); | ||
} | ||
|
||
async get_version() { | ||
console.log("GET"); | ||
} | ||
|
||
async set_version(version) { | ||
console.log("Version", version); | ||
} | ||
|
||
async execute_batch(sql) { | ||
console.log(sql); | ||
// localStorage.setItem("sql", sql); | ||
await sqlite3.exec(this.db, sql); | ||
} | ||
|
||
async execute(sql, params) { | ||
console.log(sql, params); | ||
for await (const stmt of sqlite3.statements(this.db, sql)) { | ||
let rc = sqlite3.bind_collection(stmt, params); | ||
|
||
while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) { | ||
console.log(rc); | ||
} | ||
} | ||
|
||
// localStorage.setItem("sql", sql); | ||
// await sqlite3.exec(this.db, sql); | ||
} | ||
|
||
async query_map(sql) { | ||
let rows = []; | ||
for await (const stmt of sqlite3.statements(this.db, sql)) { | ||
while ((await sqlite3.step(stmt)) === SQLite.SQLITE_ROW) { | ||
const row = sqlite3.row(stmt); | ||
rows.push(row); | ||
} | ||
} | ||
return rows; | ||
} | ||
} | ||
|
||
window.SqliteDatabase = SqliteDatabase; | ||
|
||
runTests(); |
Oops, something went wrong.