Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use crate::{
ResultBench,
};
use spacetimedb::db::relational_db::{open_db, RelationalDB};
use spacetimedb::{
db::datastore::traits::{IndexDef, TableDef},
execution_context::ExecutionContext,
};
use spacetimedb::execution_context::ExecutionContext;
use spacetimedb_lib::sats::db::def::{IndexDef, TableDef};
use spacetimedb_lib::sats::AlgebraicValue;
use spacetimedb_primitives::{ColId, TableId};
use std::hint::black_box;
Expand Down
2 changes: 2 additions & 0 deletions crates/bindings-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ proc-macro = true
bench = false

[dependencies]
spacetimedb-primitives = { path = "../primitives", version = "0.7.3" }

bitflags.workspace = true
humantime.workspace = true
proc-macro2.workspace = true
Expand Down
31 changes: 6 additions & 25 deletions crates/bindings-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ extern crate proc_macro;
use std::collections::HashMap;
use std::time::Duration;

use bitflags::{bitflags, Flags};
use bitflags::Flags;
use module::{derive_deserialize, derive_satstype, derive_serialize};
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote, quote_spanned, TokenStreamExt};
use spacetimedb_primitives::ColumnIndexAttribute;
use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;
use syn::{
Expand Down Expand Up @@ -302,7 +303,7 @@ fn gen_reducer(original_function: ItemFn, reducer_name: &str, extra: ReducerExtr
// // TODO: better (non-string-based) validation for these
// if !matches!(
// &*arg1.to_token_stream().to_string(),
// "spacetimedb::spacetimedb_lib::hash::Hash" | "Hash"
// "spacetimedb::spacetimedb_sats::hash::Hash" | "Hash"
// ) {
// return Err(syn::Error::new_spanned(
// &arg1,
Expand Down Expand Up @@ -435,26 +436,6 @@ struct Column<'a> {
attr: ColumnIndexAttribute,
}

// TODO: any way to avoid duplication with same structure in bindings crate? Extra crate?
bitflags! {
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)]
struct ColumnIndexAttribute: u8 {
const UNSET = Self::empty().bits();
/// Index no unique
const INDEXED = 0b0001;
/// Generate the next [Sequence]
const AUTO_INC = 0b0010;
/// Index unique
const UNIQUE = Self::INDEXED.bits() | 0b0100;
/// Unique + AutoInc
const IDENTITY = Self::UNIQUE.bits() | Self::AUTO_INC.bits();
/// Primary key column (implies Unique)
const PRIMARY_KEY = Self::UNIQUE.bits() | 0b1000;
/// PrimaryKey + AutoInc
const PRIMARY_KEY_AUTO = Self::PRIMARY_KEY.bits() | Self::AUTO_INC.bits();
}
}

fn spacetimedb_table(item: TokenStream) -> syn::Result<TokenStream> {
Ok(quote! {
#[derive(spacetimedb::TableType)]
Expand Down Expand Up @@ -613,7 +594,7 @@ fn spacetimedb_tabletype_impl(item: syn::DeriveInput) -> syn::Result<TokenStream
let name = name.as_deref().unwrap_or("default_index");
indexes.push(quote!(spacetimedb::IndexDef {
name: #name,
ty: spacetimedb::spacetimedb_lib::IndexType::#ty,
ty: spacetimedb::sats::db::def::IndexType::#ty,
col_ids: &[#(#col_ids),*],
}));
}
Expand Down Expand Up @@ -725,8 +706,8 @@ fn spacetimedb_tabletype_impl(item: syn::DeriveInput) -> syn::Result<TokenStream
let tabletype_impl = quote! {
impl spacetimedb::TableType for #original_struct_ident {
const TABLE_NAME: &'static str = #table_name;
const COLUMN_ATTRS: &'static [spacetimedb::spacetimedb_lib::ColumnIndexAttribute] = &[
#(spacetimedb::spacetimedb_lib::ColumnIndexAttribute::#column_attrs),*
const COLUMN_ATTRS: &'static [spacetimedb::sats::db::attr::ColumnIndexAttribute] = &[
#(spacetimedb::sats::db::attr::ColumnIndexAttribute::#column_attrs),*
];
const INDEXES: &'static [spacetimedb::IndexDef<'static>] = &[#(#indexes),*];
type InsertResult = #insert_result;
Expand Down
1 change: 1 addition & 0 deletions crates/bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spacetimedb-primitives = { path = "../primitives", version = "0.7.3" }

derive_more.workspace = true
log.workspace = true
nonempty.workspace = true
once_cell.workspace = true
scoped-tls.workspace = true

Expand Down
4 changes: 3 additions & 1 deletion crates/bindings/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use spacetimedb_lib::{Address, DataKey, Hash, Identity};
use spacetimedb_lib::{Address, Identity};

use super::PrimaryKey;
use crate::sats::data_key::DataKey;
use crate::sats::hash::Hash;
use crate::{FilterableValue, UniqueValue};

macro_rules! impl_primitives {
Expand Down
21 changes: 10 additions & 11 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ pub mod rt;
pub mod time_span;
mod timestamp;

use crate::sats::db::def::IndexType;
use spacetimedb_lib::buffer::{BufReader, BufWriter, Cursor, DecodeError};
pub use spacetimedb_lib::de::{Deserialize, DeserializeOwned};
use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, impl_st};
pub use spacetimedb_lib::ser::Serialize;
use spacetimedb_lib::{bsatn, ColumnIndexAttribute, IndexType, PrimaryKey, ProductType, ProductValue};
use spacetimedb_lib::{bsatn, PrimaryKey, ProductType, ProductValue};
use spacetimedb_primitives::ColumnIndexAttribute;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::slice::from_ref;
use std::{fmt, panic};
use sys::{Buffer, BufferIter};

pub use spacetimedb_bindings_macro::{duration, query, spacetimedb, TableType};

pub use log;
pub use sats::SpacetimeType;
pub use spacetimedb_bindings_macro::{duration, query, spacetimedb, TableType};
pub use spacetimedb_bindings_sys as sys;
pub use spacetimedb_lib;
pub use spacetimedb_lib::de::{Deserialize, DeserializeOwned};
pub use spacetimedb_lib::sats;
pub use spacetimedb_lib::ser::Serialize;
pub use spacetimedb_lib::Address;
pub use spacetimedb_lib::AlgebraicValue;
pub use spacetimedb_lib::Identity;
pub use spacetimedb_primitives::TableId;
pub use timestamp::Timestamp;

pub use spacetimedb_bindings_sys as sys;
pub use sys::Errno;
use sys::{Buffer, BufferIter};

pub use log;
pub use timestamp::Timestamp;

pub type Result<T = (), E = Errno> = core::result::Result<T, E>;

Expand Down
5 changes: 2 additions & 3 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use std::marker::PhantomData;
use std::sync::Mutex;
use std::time::Duration;

use crate::sats::db::auth::{StAccess, StTableType};
use crate::timestamp::with_timestamp_set;
use crate::{sys, ReducerContext, ScheduleToken, SpacetimeType, TableType, Timestamp};
use spacetimedb_lib::auth::{StAccess, StTableType};
pub use once_cell::sync::{Lazy, OnceCell};
use spacetimedb_lib::de::{self, Deserialize, SeqProductAccess};
use spacetimedb_lib::sats::typespace::TypespaceBuilder;
use spacetimedb_lib::sats::{impl_deserialize, impl_serialize, AlgebraicType, AlgebraicTypeRef, ProductTypeElement};
Expand All @@ -18,8 +19,6 @@ use spacetimedb_lib::{bsatn, Address, Identity, MiscModuleExport, ModuleDef, Red
use spacetimedb_primitives::TableId;
use sys::Buffer;

pub use once_cell::sync::{Lazy, OnceCell};

/// The `sender` invokes `reducer` at `timestamp` and provides it with the given `args`.
///
/// The `epilogue` is executed after `reducer` has finished.
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use super::util::fmt_fn;
use std::fmt::{self, Write};

use convert_case::{Case, Casing};
use spacetimedb_lib::sats::db::attr::ColumnIndexAttribute;
use spacetimedb_lib::sats::{
AlgebraicType, AlgebraicType::Builtin, AlgebraicTypeRef, ArrayType, BuiltinType, MapType, ProductType, SumType,
};
use spacetimedb_lib::{ColumnIndexAttribute, ProductTypeElement, ReducerDef, TableDef};
use spacetimedb_lib::{ProductTypeElement, ReducerDef, TableDef};

use super::code_indenter::CodeIndenter;
use super::{GenCtx, GenItem, INDENT};
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/generate/python.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::util::fmt_fn;

use convert_case::{Case, Casing};
use spacetimedb_lib::sats::db::attr::ColumnIndexAttribute;
use spacetimedb_lib::{
sats::{AlgebraicType::Builtin, AlgebraicTypeRef, ArrayType, BuiltinType, MapType},
AlgebraicType, ColumnIndexAttribute, ProductType, ProductTypeElement, ReducerDef, SumType, TableDef,
AlgebraicType, ProductType, ProductTypeElement, ReducerDef, SumType, TableDef,
};
use std::fmt::{self, Write};

Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/generate/rust.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::code_indenter::CodeIndenter;
use super::{GenCtx, GenItem};
use convert_case::{Case, Casing};
use spacetimedb_lib::sats::db::attr::ColumnIndexAttribute;
use spacetimedb_lib::sats::{
AlgebraicType, AlgebraicTypeRef, ArrayType, BuiltinType, MapType, ProductType, ProductTypeElement, SumType,
SumTypeVariant,
};
use spacetimedb_lib::{ColumnIndexAttribute, ReducerDef, TableDef};
use spacetimedb_lib::{ReducerDef, TableDef};
use std::collections::HashSet;
use std::fmt::Write;

Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/generate/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use super::util::fmt_fn;
use std::fmt::{self, Write};

use convert_case::{Case, Casing};
use spacetimedb_lib::sats::db::attr::ColumnIndexAttribute;
use spacetimedb_lib::sats::{
AlgebraicType, AlgebraicType::Builtin, AlgebraicTypeRef, ArrayType, BuiltinType, MapType, ProductType,
ProductTypeElement, SumType, SumTypeVariant,
};
use spacetimedb_lib::{ColumnIndexAttribute, ReducerDef, TableDef};
use spacetimedb_lib::{ReducerDef, TableDef};

use super::code_indenter::CodeIndenter;
use super::{GenCtx, GenItem, INDENT};
Expand Down
2 changes: 2 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ default = ["odb_sled"]

[dev-dependencies]
spacetimedb-lib = { path = "../lib", features = ["proptest"] }
spacetimedb-sats = { path = "../sats", features = ["proptest"] }

rusqlite.workspace = true
criterion.workspace = true
# Also as dev-dependencies for use in _this_ crate's tests.
proptest.workspace = true
proptest-derive.workspace = true
rand.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/client/messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use base64::Engine;
use prost::Message as _;
use spacetimedb_client_api_messages::client_api::{OneOffQueryResponse, OneOffTable};
use spacetimedb_lib::{relation::MemTable, Address};

use crate::host::module_host::{DatabaseUpdate, EventStatus, ModuleEvent};
use crate::identity::Identity;
Expand All @@ -10,6 +8,9 @@ use crate::json::client_api::{
TransactionUpdateJson,
};
use crate::protobuf::client_api::{event, message, Event, FunctionCall, IdentityToken, Message, TransactionUpdate};
use spacetimedb_client_api_messages::client_api::{OneOffQueryResponse, OneOffTable};
use spacetimedb_lib::Address;
use spacetimedb_sats::relation::MemTable;

use super::{DataMessage, Protocol};

Expand Down
9 changes: 3 additions & 6 deletions crates/core/src/db/commit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ use crate::{
};

use anyhow::Context;
use spacetimedb_lib::{
hash::{hash_bytes, Hash},
DataKey,
};
use spacetimedb_sats::hash::{hash_bytes, Hash};

use spacetimedb_sats::DataKey;
use std::io;
use std::sync::Arc;
use std::sync::{Mutex, MutexGuard};
Expand Down Expand Up @@ -357,11 +355,10 @@ impl From<message_log::Segments> for Iter {
#[cfg(test)]
mod tests {
use super::*;

use spacetimedb_lib::data_key::InlineData;
use tempfile::TempDir;

use crate::db::ostorage::memory_object_db::MemoryObjectDB;
use spacetimedb_sats::data_key::InlineData;

#[test]
fn test_iter_commits() {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/db/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::RangeBounds;

use crate::error::DBError;
use spacetimedb_lib::relation::{DbTable, RowCount};
use spacetimedb_sats::relation::{DbTable, RowCount};
use spacetimedb_sats::{AlgebraicValue, ProductValue};

use super::datastore::locking_tx_datastore::{Iter, IterByColRange};
Expand Down
11 changes: 4 additions & 7 deletions crates/core/src/db/datastore/locking_tx_datastore/btree_index.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use super::RowId;
use crate::{
db::datastore::locking_tx_datastore::Table,
db::datastore::traits::IndexSchema,
error::{DBError, IndexError},
};
use crate::db::datastore::locking_tx_datastore::table::Table;
use crate::error::{DBError, IndexError};
use nonempty::NonEmpty;
use spacetimedb_lib::{data_key::ToDataKey, DataKey, IndexType};
use spacetimedb_primitives::{ColId, IndexId, TableId};
use spacetimedb_sats::{AlgebraicValue, ProductValue};
use spacetimedb_sats::db::def::{IndexSchema, IndexType};
use spacetimedb_sats::{data_key::ToDataKey, AlgebraicValue, DataKey, ProductValue};
use std::{
collections::{btree_set, BTreeSet},
ops::{Bound, RangeBounds},
Expand Down
Loading