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

Method generate_table_file_from_schema

crates/codegen/src/cpp.rs:481–516  ·  view source on GitHub ↗
(
        &self,
        module: &ModuleDef,
        table: &TableDef,
        _schema: TableSchema,
    )

Source from the content-addressed store, hash-verified

479
480impl Lang for Cpp<'_> {
481 fn generate_table_file_from_schema(
482 &self,
483 module: &ModuleDef,
484 table: &TableDef,
485 _schema: TableSchema,
486 ) -> OutputFile {
487 let mut output = String::new();
488 self.write_header_comment(&mut output);
489 self.write_standard_includes(&mut output);
490
491 // Add includes for dependencies
492 if let Some(AlgebraicTypeDef::Product(product)) = module.typespace_for_generate().get(table.product_type_ref) {
493 let deps = self.collect_product_dependencies(module, product);
494 for dep in deps {
495 if dep != table.name.to_string() {
496 writeln!(output, "#include \"{}.g.h\"", dep).unwrap();
497 }
498 }
499 }
500
501 writeln!(output).unwrap();
502 writeln!(output, "namespace {} {{", self.namespace).unwrap();
503 writeln!(output).unwrap();
504
505 // Generate table as a product type
506 if let Some(AlgebraicTypeDef::Product(product)) = module.typespace_for_generate().get(table.product_type_ref) {
507 self.write_product_type(&mut output, module, &table.name, product);
508 }
509
510 writeln!(output, "}} // namespace {}", self.namespace).unwrap();
511
512 OutputFile {
513 filename: format!("{}.g.h", table.name),
514 code: output,
515 }
516 }
517
518 fn generate_type_files(&self, module: &ModuleDef, type_def: &TypeDef) -> Vec<OutputFile> {
519 let mut output = String::new();

Callers 2

generate_table_fileMethod · 0.45
generate_view_fileMethod · 0.45

Calls 9

write_header_commentMethod · 0.80
write_product_typeMethod · 0.80
newFunction · 0.50
getMethod · 0.45
to_stringMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected