(mut row: T::Row, mut buf: IterBuf)
| 1348 | /// Insert a row of type `T` into the table identified by `table_id`. |
| 1349 | #[track_caller] |
| 1350 | fn insert<T: Table>(mut row: T::Row, mut buf: IterBuf) -> Result<T::Row, TryInsertError<T>> { |
| 1351 | let table_id = T::table_id(); |
| 1352 | // Encode the row as bsatn into the buffer `buf`. |
| 1353 | buf.clear(); |
| 1354 | buf.serialize_into(&row).unwrap(); |
| 1355 | |
| 1356 | // Insert row into table. |
| 1357 | // When table has an auto-incrementing column, we must re-decode the changed `buf`. |
| 1358 | let res = sys::datastore_insert_bsatn(table_id, &mut buf).map(|gen_cols| { |
| 1359 | // Let the caller handle any generated columns written back by `sys::datastore_insert_bsatn` to `buf`. |
| 1360 | T::integrate_generated_columns(&mut row, gen_cols); |
| 1361 | row |
| 1362 | }); |
| 1363 | res.map_err(|e| { |
| 1364 | let err = match e { |
| 1365 | sys::Errno::UNIQUE_ALREADY_EXISTS => { |
| 1366 | T::UniqueConstraintViolation::get().map(TryInsertError::UniqueConstraintViolation) |
| 1367 | } |
| 1368 | sys::Errno::AUTO_INC_OVERFLOW => T::AutoIncOverflow::get().map(TryInsertError::AutoIncOverflow), |
| 1369 | _ => None, |
| 1370 | }; |
| 1371 | err.unwrap_or_else(|| panic!("unexpected insertion error: {e}")) |
| 1372 | }) |
| 1373 | } |
| 1374 | |
| 1375 | /// Update a row of type `T` to `row` using the index identified by `index_id`. |
| 1376 | #[track_caller] |
nothing calls this directly
no test coverage detected
searching dependent graphs…