Skip to content
Merged
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
35 changes: 33 additions & 2 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,14 @@ pub trait DbContext {
///
/// This method is provided for times when a programmer wants to be generic over the `DbContext` type.
/// Concrete-typed code is expected to read the `.db` field off the particular `DbContext` implementor.
/// Currently, being this generic is only meaningful in clients,
/// as `ReducerContext` is the only implementor of `DbContext` within modules.
fn db(&self) -> &Self::DbView;

/// Get a read-only view into the tables.
///
/// This method is provided for times when a programmer wants to be generic over the `DbContext` type.
/// Concrete-typed code is expected to read the `.db` field off the particular `DbContext` implementor.
#[cfg(feature = "unstable")]
fn db_read_only(&self) -> &LocalReadOnly;
}

impl DbContext for AnonymousViewContext {
Expand All @@ -1468,6 +1473,11 @@ impl DbContext for AnonymousViewContext {
fn db(&self) -> &Self::DbView {
&self.db
}

#[cfg(feature = "unstable")]
fn db_read_only(&self) -> &LocalReadOnly {
&self.db
}
}

impl DbContext for ReducerContext {
Expand All @@ -1476,6 +1486,11 @@ impl DbContext for ReducerContext {
fn db(&self) -> &Self::DbView {
&self.db
}

#[cfg(feature = "unstable")]
fn db_read_only(&self) -> &LocalReadOnly {
self.db.get_read_only()
}
}

#[cfg(feature = "unstable")]
Expand All @@ -1485,6 +1500,10 @@ impl DbContext for TxContext {
fn db(&self) -> &Self::DbView {
&self.db
}

fn db_read_only(&self) -> &LocalReadOnly {
self.db.get_read_only()
}
}

impl DbContext for ViewContext {
Expand All @@ -1493,6 +1512,11 @@ impl DbContext for ViewContext {
fn db(&self) -> &Self::DbView {
&self.db
}

#[cfg(feature = "unstable")]
fn db_read_only(&self) -> &LocalReadOnly {
&self.db
}
}

// `ProcedureContext` is *not* a `DbContext`
Expand All @@ -1506,6 +1530,13 @@ impl DbContext for ViewContext {
#[non_exhaustive]
pub struct Local {}

impl Local {
#[cfg(feature = "unstable")]
fn get_read_only(&self) -> &LocalReadOnly {
&LocalReadOnly {}
}
}

/// The [JWT] of an [`AuthCtx`].
///
/// [JWT]: https://en.wikipedia.org/wiki/JSON_Web_Token
Expand Down
Loading