diff --git a/crates/lib/src/filterable_value.rs b/crates/lib/src/filterable_value.rs index 82a90eb7c4e..48a9d314716 100644 --- a/crates/lib/src/filterable_value.rs +++ b/crates/lib/src/filterable_value.rs @@ -1,6 +1,8 @@ use crate::{ConnectionId, Identity}; use core::ops; use spacetimedb_sats::bsatn; +use spacetimedb_sats::time_duration::TimeDuration; +use spacetimedb_sats::timestamp::Timestamp; use spacetimedb_sats::{hash::Hash, i256, u256, Serialize}; /// Types which can appear as an argument to an index filtering operation @@ -97,6 +99,9 @@ impl_filterable_value! { ConnectionId: Copy, Hash: Copy, + Timestamp: Copy, + TimeDuration: Copy, + // Some day we will likely also want to support `Vec` and `[u8]`, // as they have trivial portable equality and ordering, // but @RReverser's proposed filtering rules do not include them. diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index d3c5e81404b..bf13692d3c8 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -89,6 +89,22 @@ pub enum TestF { Baz(String), } +#[spacetimedb::table( + name = test_g, + index(name = created_at_index, btree(columns = [name, created_at])), +)] +#[derive(Debug)] +pub struct TestG { + #[primary_key] + #[auto_inc] + id: u64, + + name: String, + + #[index(btree)] + created_at: Timestamp, +} + // // All tables are private by default. const _: () = assert!(matches!(get_table_access(test_e::test_e), TableAccess::Private)); @@ -363,6 +379,9 @@ fn test_btree_index_args(ctx: &ReducerContext) { ctx.db.test_e().name().delete(&string); ctx.db.test_e().name().delete("str"); + // Testing if it compiles with a range of timestamps. + let _ = ctx.db.test_g().created_at().filter(..ctx.timestamp); + // ctx.db.test_e().name().delete(string); // SHOULD FAIL // Multi-column i64 index on `points.x, points.y`: diff --git a/modules/sdk-test-cs/Lib.cs b/modules/sdk-test-cs/Lib.cs index 7ece58f476a..f68a3d816b4 100644 --- a/modules/sdk-test-cs/Lib.cs +++ b/modules/sdk-test-cs/Lib.cs @@ -320,6 +320,7 @@ public static void insert_one_connection_id(ReducerContext ctx, ConnectionId a) [SpacetimeDB.Table(Name = "one_timestamp", Public = true)] public partial struct OneTimestamp { + [SpacetimeDB.Index.BTree] public Timestamp t; } @@ -327,6 +328,8 @@ public partial struct OneTimestamp public static void insert_one_timestamp(ReducerContext ctx, Timestamp t) { ctx.Db.one_timestamp.Insert(new OneTimestamp { t = t }); + + var _count = ctx.Db.one_timestamp.t.Filter((t, ctx.Timestamp)).Count(); } [SpacetimeDB.Table(Name = "one_simple_enum", Public = true)]