Skip to content

Commit dc5a236

Browse files
authored
Add get primary key value/type functions to csharp autogen code (#118)
1 parent 9143508 commit dc5a236

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/cli/src/subcommands/generate/csharp.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,37 @@ fn autogen_csharp_access_funcs_for_struct(
11131113
.unwrap();
11141114
}
11151115
writeln!(output, "}}").unwrap();
1116+
writeln!(output).unwrap();
1117+
1118+
writeln!(
1119+
output,
1120+
"public static SpacetimeDB.SATS.AlgebraicValue GetPrimaryKeyValue(SpacetimeDB.SATS.AlgebraicValue v)"
1121+
)
1122+
.unwrap();
1123+
writeln!(output, "{{").unwrap();
1124+
{
1125+
indent_scope!(output);
1126+
writeln!(output, "return v.AsProductValue().elements[{}];", primary_col_index).unwrap();
1127+
}
1128+
writeln!(output, "}}").unwrap();
1129+
writeln!(output).unwrap();
1130+
1131+
writeln!(
1132+
output,
1133+
"public static SpacetimeDB.SATS.AlgebraicType GetPrimaryKeyType(SpacetimeDB.SATS.AlgebraicType t)"
1134+
)
1135+
.unwrap();
1136+
writeln!(output, "{{").unwrap();
1137+
{
1138+
indent_scope!(output);
1139+
writeln!(
1140+
output,
1141+
"return t.product.elements[{}].algebraicType;",
1142+
primary_col_index
1143+
)
1144+
.unwrap();
1145+
}
1146+
writeln!(output, "}}").unwrap();
11161147
} else {
11171148
writeln!(
11181149
output,

0 commit comments

Comments
 (0)