Skip to content

How do i obtain a last inserted ID while inserting? #20

Answered by devashishdxt
afidegnum asked this question in Q&A
Discussion options

You must be logged in to vote

Seems like you're using auto_increment IDs. If you go in the readme, you can see that Store::add returns the ID of the added object.

Here is the example from readme:

use rexie::*;

async fn add_employee(rexie: &Rexie, name: &str, email: &str) -> Result<u32> {
    // Create a new read-write transaction
    let transaction = rexie.transaction(&["employees"], TransactionMode::ReadWrite)?;

    // Get the `employees` store
    let employees = transaction.store("employees")?;

    // Create an employee
    let employee = serde_json::json!({
        "name": name,
        "email": email,
    });
    // Convert it to `JsValue`
    let employee = serde_wasm_bindgen::to_value(&employee).unwrap();

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@afidegnum
Comment options

@afidegnum
Comment options

@afidegnum
Comment options

Answer selected by devashishdxt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants