Skip to content

Commit 8066ac8

Browse files
committed
Merge branch 'master' into phoebe/remove-memtable-from-plans
2 parents d75ef7c + e54b09b commit 8066ac8

File tree

18 files changed

+352
-467
lines changed

18 files changed

+352
-467
lines changed

crates/bench/benches/subscription.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use spacetimedb::subscription::query::compile_read_only_query;
77
use spacetimedb::subscription::subscription::ExecutionSet;
88
use spacetimedb_lib::identity::AuthCtx;
99
use spacetimedb_primitives::TableId;
10-
use spacetimedb_sats::{product, AlgebraicType, AlgebraicValue, ProductValue, ToDataKey};
10+
use spacetimedb_sats::{product, AlgebraicType, AlgebraicValue, ProductValue};
1111
use tempdir::TempDir;
1212

1313
fn create_table_location(db: &RelationalDB) -> Result<TableId, DBError> {
@@ -39,15 +39,10 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
3939
}
4040

4141
fn insert_op(table_id: TableId, table_name: &str, row: ProductValue) -> DatabaseTableUpdate {
42-
let row_pk = row.to_data_key().to_bytes();
4342
DatabaseTableUpdate {
4443
table_id,
4544
table_name: table_name.to_string(),
46-
ops: vec![TableOp {
47-
op_type: 1,
48-
row,
49-
row_pk,
50-
}],
45+
ops: vec![TableOp::insert(row)],
5146
}
5247
}
5348

crates/bindings/src/impls.rs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,13 @@
1-
use spacetimedb_lib::{Address, Identity};
2-
3-
use super::PrimaryKey;
4-
use crate::sats::data_key::DataKey;
51
use crate::sats::hash::Hash;
6-
use crate::{FilterableValue, UniqueValue};
2+
use crate::FilterableValue;
3+
use spacetimedb_lib::{Address, Identity};
74

85
macro_rules! impl_primitives {
9-
(uniq { $($t:ty => $x:ident,)*}) => {
6+
($($t:ty),*) => {
107
$(
118
impl FilterableValue for $t {}
12-
impl UniqueValue for $t {
13-
fn into_primarykey(self) -> PrimaryKey {
14-
todo!() // idk what this is
15-
}
16-
}
179
)*
1810
};
1911
}
2012

21-
impl FilterableValue for u8 {}
22-
impl UniqueValue for u8 {
23-
fn into_primarykey(self) -> PrimaryKey {
24-
todo!() // idk what this is
25-
}
26-
}
27-
28-
impl_primitives! {
29-
uniq {
30-
i8 => I8,
31-
u16 => U16,
32-
i16 => I16,
33-
u32 => U32,
34-
i32 => I32,
35-
u64 => U64,
36-
i64 => I64,
37-
u128 => U128,
38-
i128 => I128,
39-
bool => Bool,
40-
String => String,
41-
}
42-
}
43-
44-
impl FilterableValue for Hash {}
45-
impl UniqueValue for Hash {
46-
fn into_primarykey(self) -> PrimaryKey {
47-
PrimaryKey {
48-
data_key: DataKey::Hash(self),
49-
}
50-
}
51-
}
52-
53-
impl FilterableValue for Identity {}
54-
impl UniqueValue for Identity {
55-
fn into_primarykey(self) -> PrimaryKey {
56-
todo!() // idk what this is
57-
}
58-
}
59-
60-
impl FilterableValue for Address {}
61-
impl UniqueValue for Address {
62-
fn into_primarykey(self) -> PrimaryKey {
63-
todo!()
64-
}
65-
}
13+
impl_primitives![u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, bool, String, Hash, Identity, Address];

crates/bindings/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ pub mod rt;
1010
pub mod time_span;
1111
mod timestamp;
1212

13+
use crate::sats::db::attr::ColumnAttribute;
1314
use crate::sats::db::def::IndexType;
1415
use spacetimedb_lib::buffer::{BufReader, BufWriter, Cursor, DecodeError};
1516
use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, impl_st};
16-
use spacetimedb_lib::{bsatn, PrimaryKey, ProductType, ProductValue};
17+
use spacetimedb_lib::{bsatn, ProductType, ProductValue};
1718
use std::cell::RefCell;
1819
use std::marker::PhantomData;
1920
use std::slice::from_ref;
2021
use std::{fmt, panic};
2122
use sys::{Buffer, BufferIter};
2223

23-
use crate::sats::db::attr::ColumnAttribute;
2424
pub use log;
2525
pub use sats::SpacetimeType;
2626
pub use spacetimedb_bindings_macro::{duration, query, spacetimedb, TableType};
@@ -440,11 +440,6 @@ impl<T: TableType> sealed::InsertResult for T {
440440
/// then so are the values in their serialized representation.
441441
pub trait FilterableValue: Serialize + Eq {}
442442

443-
/// A trait for types that can be converted into primary keys.
444-
pub trait UniqueValue: FilterableValue {
445-
fn into_primarykey(self) -> PrimaryKey;
446-
}
447-
448443
#[doc(hidden)]
449444
pub mod query {
450445
use super::*;
@@ -470,7 +465,7 @@ pub mod query {
470465
#[doc(hidden)]
471466
pub fn filter_by_unique_field<
472467
Table: TableType + FieldAccess<COL_IDX, Field = T>,
473-
T: UniqueValue,
468+
T: FilterableValue,
474469
const COL_IDX: u8,
475470
>(
476471
val: &T,
@@ -531,7 +526,7 @@ pub mod query {
531526
/// **NOTE:** Do not use directly.
532527
/// This is exposed as `delete_by_{$field_name}` on types with `#[spacetimedb(table)]`
533528
/// where the field has a unique constraint.
534-
pub fn delete_by_unique_field<Table: TableType, T: UniqueValue, const COL_IDX: u8>(val: &T) -> bool {
529+
pub fn delete_by_unique_field<Table: TableType, T: FilterableValue, const COL_IDX: u8>(val: &T) -> bool {
535530
let count = delete_by_field::<Table, T, COL_IDX>(val);
536531
debug_assert!(count <= 1);
537532
count > 0
@@ -545,7 +540,7 @@ pub mod query {
545540
/// **NOTE:** Do not use directly.
546541
/// This is exposed as `update_by_{$field_name}` on types with `#[spacetimedb(table)]`.
547542
#[doc(hidden)]
548-
pub fn update_by_field<Table: TableType, T: UniqueValue, const COL_IDX: u8>(old: &T, new: Table) -> bool {
543+
pub fn update_by_field<Table: TableType, T: FilterableValue, const COL_IDX: u8>(old: &T, new: Table) -> bool {
549544
// Delete the existing row, if any.
550545
delete_by_field::<Table, T, COL_IDX>(old);
551546

crates/core/src/db/relational_db.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use crate::execution_context::ExecutionContext;
1919
use crate::hash::Hash;
2020
use fs2::FileExt;
2121
use itertools::Itertools;
22-
use spacetimedb_lib::PrimaryKey;
2322
use spacetimedb_primitives::*;
24-
use spacetimedb_sats::data_key::ToDataKey;
2523
use spacetimedb_sats::db::auth::{StAccess, StTableType};
2624
use spacetimedb_sats::db::def::{ColumnDef, IndexDef, SequenceDef, TableDef, TableSchema};
2725
use spacetimedb_sats::{AlgebraicType, AlgebraicValue, ProductType, ProductValue};
@@ -185,12 +183,6 @@ impl RelationalDB {
185183
.map_or(Ok(0), |commit_log| commit_log.object_db_size_on_disk())
186184
}
187185

188-
pub fn pk_for_row(row: &ProductValue) -> PrimaryKey {
189-
PrimaryKey {
190-
data_key: row.to_data_key(),
191-
}
192-
}
193-
194186
#[tracing::instrument(skip_all)]
195187
pub fn encode_row(row: &ProductValue, bytes: &mut Vec<u8>) {
196188
// TODO: large file storage of the row elements
@@ -589,7 +581,6 @@ impl RelationalDB {
589581
/// where the column data identified by `cols` matches `value`.
590582
///
591583
/// Matching is defined by `Ord for AlgebraicValue`.
592-
#[tracing::instrument(skip_all)]
593584
pub fn iter_by_col_eq_mut<'a>(
594585
&'a self,
595586
ctx: &'a ExecutionContext,
@@ -601,7 +592,6 @@ impl RelationalDB {
601592
self.inner.iter_by_col_eq_mut_tx(ctx, tx, table_id.into(), cols, value)
602593
}
603594

604-
#[tracing::instrument(skip_all)]
605595
pub fn iter_by_col_eq<'a>(
606596
&'a self,
607597
ctx: &'a ExecutionContext,

crates/core/src/error.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use thiserror::Error;
1212
use crate::client::ClientActorId;
1313
use crate::db::datastore::system_tables::SystemTable;
1414
use spacetimedb_lib::buffer::DecodeError;
15-
use spacetimedb_lib::{PrimaryKey, ProductValue};
15+
use spacetimedb_lib::ProductValue;
1616
use spacetimedb_primitives::*;
1717
use spacetimedb_sats::db::def::IndexDef;
1818
use spacetimedb_sats::db::error::{LibError, RelationError, SchemaErrors};
@@ -313,8 +313,6 @@ pub enum NodesError {
313313
DecodeFilter(#[source] DecodeError),
314314
#[error("table with provided name or id doesn't exist")]
315315
TableNotFound,
316-
#[error("Primary key {0:?} not found")]
317-
PrimaryKeyNotFound(PrimaryKey),
318316
#[error("row with column of given value not found")]
319317
ColumnValueNotFound,
320318
#[error("range of rows not found")]

0 commit comments

Comments
 (0)