Skip to content

Commit

Permalink
Implement select
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Jul 29, 2024
1 parent 431f3a5 commit 4dfc556
Show file tree
Hide file tree
Showing 23 changed files with 5,049 additions and 84 deletions.
44 changes: 27 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=0
bitwarden-cli = { path = "crates/bitwarden-cli", version = "=0.5.0" }
bitwarden-core = { path = "crates/bitwarden-core", version = "=0.5.0" }
bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=0.5.0" }
bitwarden-db = { path = "crates/bitwarden-db", version = "=0.5.0" }
bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=0.5.0" }
bitwarden-fido = { path = "crates/bitwarden-fido", version = "=0.5.0" }
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=0.5.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ base64 = ">=0.22.1, <0.23"
bitwarden-api-api = { workspace = true }
bitwarden-api-identity = { workspace = true }
bitwarden-crypto = { workspace = true }
bitwarden-db = { workspace = true }
chrono = { version = ">=0.4.26, <0.5", features = [
"clock",
"serde",
Expand Down Expand Up @@ -72,7 +73,6 @@ wasm-bindgen = { version = "0.2.91", features = [
"serde-serialize",
], optional = true }
wasm-bindgen-futures = "0.4.41"
js-sys = "0.3.69"


[target.'cfg(all(not(target_os = "android"), not(target_arch="wasm32")))'.dependencies]
Expand Down
10 changes: 4 additions & 6 deletions crates/bitwarden-core/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::sync::{Arc, Mutex, RwLock};

use bitwarden_db::Database;
use reqwest::header::{self, HeaderValue};

use super::internal::InternalClient;
#[cfg(feature = "internal")]
use crate::client::flags::Flags;
use crate::{
client::{
client_settings::ClientSettings,
internal::{ApiConfigurations, Tokens},
},
Database,
use crate::client::{
client_settings::ClientSettings,
internal::{ApiConfigurations, Tokens},
};

/// The main struct to interact with the Bitwarden SDK.
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-core/src/client/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::{Arc, Mutex, RwLock};
use bitwarden_crypto::SymmetricCryptoKey;
#[cfg(feature = "internal")]
use bitwarden_crypto::{AsymmetricEncString, EncString, Kdf, MasterKey};
use bitwarden_db::Database;
use chrono::Utc;
use uuid::Uuid;

Expand All @@ -17,7 +18,7 @@ use crate::error::Error;
use crate::{
auth::renew::renew_token,
error::{Result, VaultLocked},
Database, DeviceType,
DeviceType,
};

#[derive(Debug, Clone)]
Expand Down
2 changes: 0 additions & 2 deletions crates/bitwarden-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub use error::Error;
#[cfg(feature = "internal")]
pub mod mobile;
pub use error::{MissingFieldError, VaultLocked};
mod database;
pub use database::{Database, DatabaseError, DatabaseTrait, Params, ToSql};
#[cfg(feature = "internal")]
pub mod platform;
#[cfg(feature = "secrets")]
Expand Down
25 changes: 25 additions & 0 deletions crates/bitwarden-db-tests/Cargo.toml
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"
6 changes: 6 additions & 0 deletions crates/bitwarden-db-tests/bin/main.rs
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;
}
75 changes: 75 additions & 0 deletions crates/bitwarden-db-tests/index.js
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();
Loading

0 comments on commit 4dfc556

Please sign in to comment.