Skip to content

Commit ce8df93

Browse files
update view return value deserialization
1 parent a18e951 commit ce8df93

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

crates/core/src/db/relational_db.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ use spacetimedb_paths::server::{CommitLogDir, ReplicaDir, SnapshotsPath};
4444
use spacetimedb_primitives::*;
4545
use spacetimedb_sats::algebraic_type::fmt::fmt_algebraic_type;
4646
use spacetimedb_sats::memory_usage::MemoryUsage;
47-
use spacetimedb_sats::{AlgebraicType, AlgebraicTypeRef, AlgebraicValue, ProductType, ProductValue, Typespace};
47+
use spacetimedb_sats::{
48+
AlgebraicType, AlgebraicTypeRef, AlgebraicValue, ProductType, ProductValue, Typespace, WithTypespace,
49+
};
4850
use spacetimedb_schema::def::{ModuleDef, TableDef, ViewDef};
4951
use spacetimedb_schema::schema::{
5052
ColumnSchema, IndexSchema, RowLevelSecuritySchema, Schema, SequenceSchema, TableSchema,
@@ -1527,7 +1529,7 @@ impl RelationalDB {
15271529
tx: &mut MutTxId,
15281530
table_id: TableId,
15291531
sender: Identity,
1530-
return_type: AlgebraicTypeRef,
1532+
row_type: AlgebraicTypeRef,
15311533
bytes: Bytes,
15321534
typespace: &Typespace,
15331535
) -> Result<(), DBError> {
@@ -1538,8 +1540,11 @@ impl RelationalDB {
15381540
.collect::<Vec<_>>();
15391541
self.delete(tx, table_id, rows_to_delete);
15401542

1541-
// Deserialize the return rows
1542-
let seed = spacetimedb_sats::WithTypespace::new(typespace, &return_type).resolve(return_type);
1543+
// Deserialize the return rows.
1544+
// The return type is expected to be an array of products.
1545+
let row_type = typespace.resolve(row_type);
1546+
let ret_type = AlgebraicType::array(row_type.ty().clone());
1547+
let seed = WithTypespace::new(typespace, &ret_type);
15431548
let rows = seed
15441549
.deserialize(bsatn::Deserializer::new(&mut &bytes[..]))
15451550
.map_err(|e| DatastoreError::from(ViewError::DeserializeReturn(e.to_string())))?;
@@ -1593,8 +1598,11 @@ impl RelationalDB {
15931598
// Clear entire backing table
15941599
self.clear_table(tx, table_id)?;
15951600

1596-
// Deserialize the return rows
1597-
let seed = spacetimedb_sats::WithTypespace::new(typespace, &row_type).resolve(row_type);
1601+
// Deserialize the return rows.
1602+
// The return type is expected to be an array of products.
1603+
let row_type = typespace.resolve(row_type);
1604+
let ret_type = AlgebraicType::array(row_type.ty().clone());
1605+
let seed = WithTypespace::new(typespace, &ret_type);
15981606
let rows = seed
15991607
.deserialize(bsatn::Deserializer::new(&mut &bytes[..]))
16001608
.map_err(|e| DatastoreError::from(ViewError::DeserializeReturn(e.to_string())))?;

0 commit comments

Comments
 (0)