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

Function create_table_with_rows

crates/core/src/sql/execute.rs:305–352  ·  view source on GitHub ↗
(
        db: &RelationalDB,
        tx: &mut crate::db::relational_db::MutTx,
        table_name: &str,
        schema: ProductType,
        rows: &[ProductValue],
        access: StAccess,
    )

Source from the content-addressed store, hash-verified

303 }
304
305 fn create_table_with_rows(
306 db: &RelationalDB,
307 tx: &mut crate::db::relational_db::MutTx,
308 table_name: &str,
309 schema: ProductType,
310 rows: &[ProductValue],
311 access: StAccess,
312 ) -> ResultTest<Arc<TableSchema>> {
313 let columns = schema
314 .elements
315 .iter()
316 .cloned()
317 .enumerate()
318 .map(|(i, element)| ColumnSchema {
319 table_id: TableId::SENTINEL,
320 col_name: Identifier::new(element.name.unwrap()).unwrap(),
321 col_type: element.algebraic_type,
322 col_pos: ColId(i as _),
323 alias: None,
324 })
325 .collect();
326
327 let table_id = db.create_table(
328 tx,
329 TableSchema::new(
330 TableId::SENTINEL,
331 TableName::for_test(table_name),
332 None,
333 columns,
334 vec![],
335 vec![],
336 vec![],
337 StTableType::User,
338 access,
339 None,
340 None,
341 false,
342 None,
343 ),
344 )?;
345 let schema = db.schema_for_table_mut(tx, table_id)?;
346
347 for row in rows {
348 insert(db, tx, table_id, row)?;
349 }
350
351 Ok(schema)
352 }
353
354 fn create_data(total_rows: u64) -> ResultTest<(TestDB, TestRows)> {
355 let stdb = TestDB::durable()?;

Callers 3

create_dataFunction · 0.85
create_identity_tableFunction · 0.85
test_inner_joinFunction · 0.85

Calls 10

ColIdClass · 0.85
schema_for_table_mutMethod · 0.80
iterMethod · 0.65
newFunction · 0.50
insertFunction · 0.50
OkFunction · 0.50
collectMethod · 0.45
mapMethod · 0.45
unwrapMethod · 0.45
create_tableMethod · 0.45

Tested by 1

test_inner_joinFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…