Skip to content

Commit

Permalink
Update JavaScript package load_indexeddb method to get namespace as a… (
Browse files Browse the repository at this point in the history
gluesql#1320)

Update JavaScript package load_indexeddb method to get namespace as a optional param
  • Loading branch information
panarch committed Jul 22, 2023
1 parent 4788761 commit 155975a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/javascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Glue {

#[cfg(not(feature = "nodejs"))]
#[wasm_bindgen(js_name = loadIndexedDB)]
pub fn load_indexeddb(&mut self) -> Promise {
pub fn load_indexeddb(&mut self, namespace: Option<String>) -> Promise {
let cell = Rc::clone(&self.storage);

future_to_promise(async move {
Expand All @@ -84,7 +84,7 @@ impl Glue {
return Err(JsValue::from_str("indexedDB storage is already loaded"));
}

let idb_storage = match IdbStorage::new(None).await {
let idb_storage = match IdbStorage::new(namespace).await {
Ok(storage) => storage,
Err(error) => {
cell.replace(Some(storage));
Expand Down
4 changes: 2 additions & 2 deletions pkg/javascript/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ async fn error() {
))
);

let loaded = glue.load_indexeddb();
let loaded = glue.load_indexeddb(None);
JsFuture::from(loaded).await.unwrap();
assert_eq!(glue.set_default_engine("indexedDB".to_owned()), Ok(()));

let loaded = glue.load_indexeddb();
let loaded = glue.load_indexeddb(None);
assert_eq!(
JsFuture::from(loaded).await,
Err(JsValue::from_str("indexedDB storage is already loaded"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/javascript/tests/join_multiple_storages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
#[wasm_bindgen_test]
async fn join_multiple_storages() {
let mut glue = Glue::new();
let loaded = glue.load_indexeddb();
let loaded = glue.load_indexeddb(None);
JsFuture::from(loaded).await.unwrap();

let mut test = |sql: &'static str, expected| {
Expand Down

0 comments on commit 155975a

Please sign in to comment.