Skip to content

How to use the indexed_db via web-sys #1476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bigfish3000 opened this issue Apr 19, 2019 · 2 comments
Closed

How to use the indexed_db via web-sys #1476

bigfish3000 opened this issue Apr 19, 2019 · 2 comments
Labels

Comments

@bigfish3000
Copy link

How to use the indexed via web-sys, do some one have examples ?

Who can show me the examples?

I can not access the indexed_db like this:

        let db = window!().indexed_db().unwrap().unwrap();
        let opened_request = match db.open("test-my") { 
            Ok(v) => { v },
            Err(res) => { 
                let s = Array::from(&res);
                console::log(&s);
                return;
            }
        };
        let trans = match opened_request.transaction() {  
            Some(v) => { v },
            None => { 
                log_info_str!("Can not get transaction"); //It always show me error!
                return;
            }
        };
        let db = trans.db();
        let store = match db.create_object_store("my-test") { 
            Ok(v) => { v },
            Err(err) => {                 
                let s = Array::from(&err);
                console::log(&s);
                return;
            }
        };
        let js = JsValue::from("hello world");
        let _request = match store.put(&js)  { 
            Ok(v) => { v },
            Err(err) => {                 
                let s = Array::from(&err);
                console::log(&s);
                return;
            }
        };
@richard-uk1
Copy link
Contributor

indexeddb is quite complicated. Everything is done async via. callbacks, so you need to use Closure, but the memory management is fiddly. Eventually there will be a futures-based lib in https://github.com/rustwasm/gloo, in the mean time it's just gonna be hard.

@alexcrichton
Copy link
Contributor

Thanks for the question @bigfish3000! I agree with @derekdreery in that this is pretty complicated, but targeted to be covered by the gloo project! In light of that I'm gonna close this in favor of rustwasm/gloo#68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants