MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / insert

Method insert

crates/core/src/host/instance_env.rs:358–393  ·  view source on GitHub ↗
(&self, table_id: TableId, buffer: &mut [u8])

Source from the content-addressed store, hash-verified

356 }
357
358 pub fn insert(&self, table_id: TableId, buffer: &mut [u8]) -> Result<usize, NodesError> {
359 let stdb = self.relational_db();
360 let tx = &mut *self.get_tx()?;
361
362 let (row_len, row_ptr, insert_flags) = stdb
363 .insert(tx, table_id, buffer)
364 .map(|(gen_cols, row_ref, insert_flags)| {
365 let row_len = Self::project_cols_bsatn(buffer, gen_cols, row_ref);
366 (row_len, row_ref.pointer(), insert_flags)
367 })
368 .inspect_err(
369 #[cold]
370 #[inline(never)]
371 |e| match e {
372 DBError::Datastore(DatastoreError::Index(IndexError::UniqueConstraintViolation(_))) => {}
373 _ => {
374 let res = stdb.table_name_from_id_mut(tx, table_id);
375 if let Ok(Some(table_name)) = res {
376 log::debug!("insert(table: {table_name}, table_id: {table_id}): {e}")
377 } else {
378 log::debug!("insert(table_id: {table_id}): {e}")
379 }
380 }
381 },
382 )?;
383
384 if insert_flags.is_scheduler_table {
385 self.schedule_row(stdb, tx, table_id, row_ptr)?;
386 }
387
388 // Note, we update the metric for bytes written after the insert.
389 // This is to capture auto-inc columns.
390 tx.metrics.bytes_written += buffer.len();
391
392 Ok(row_len)
393 }
394
395 #[cold]
396 #[inline(never)]

Callers

nothing calls this directly

Calls 9

get_txMethod · 0.80
pointerMethod · 0.80
schedule_rowMethod · 0.80
insertMethod · 0.65
OkFunction · 0.50
relational_dbMethod · 0.45
mapMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected