How do i obtain a last inserted ID while inserting? #20
-
While creating an insert, I would like to obtain the last inserted id record which I can pass to the dom. What's the function needed? |
Beta Was this translation helpful? Give feedback.
Answered by
devashishdxt
Jun 17, 2022
Replies: 1 comment 3 replies
-
Seems like you're using 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();
// Add the employee to the store
let employee_id = employees.add(&employee, None).await?;
// Waits for the transaction to complete
transaction.done().await?;
// Return the employee id
Ok(num_traits::cast(employee_id.as_f64().unwrap()).unwrap())
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
devashishdxt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like you're using
auto_increment
IDs. If you go in the readme, you can see thatStore::add
returns the ID of the added object.Here is the example from readme: