Skip to main content

RawModuleDefV10Builder

Struct RawModuleDefV10Builder 

Source
pub struct RawModuleDefV10Builder { /* private fields */ }
Expand description

A builder for a RawModuleDefV10.

Implementations§

Source§

impl RawModuleDefV10Builder

Source

pub fn new() -> Self

Create a new, empty RawModuleDefV10Builder.

Source

pub fn add_type<T: SpacetimeType>(&mut self) -> AlgebraicType

Add a type to the in-progress module.

The returned type must satisfy AlgebraicType::is_valid_for_client_type_definition or AlgebraicType::is_valid_for_client_type_use.

Source

pub fn build_table( &mut self, source_name: impl Into<RawIdentifier>, product_type_ref: AlgebraicTypeRef, ) -> RawTableDefBuilderV10<'_>

Create a table builder.

Does not validate that the product_type_ref is valid; this is left to the module validation code.

Source

pub fn build_table_with_new_type( &mut self, table_name: impl Into<RawIdentifier>, product_type: impl Into<ProductType>, custom_ordering: bool, ) -> RawTableDefBuilderV10<'_>

Build a new table with a product type. Adds the type to the module.

Source

pub fn build_table_with_new_type_for_tests( &mut self, table_name: impl Into<RawIdentifier>, product_type: ProductType, custom_ordering: bool, ) -> RawTableDefBuilderV10<'_>

Build a new table with a product type, for testing. Adds the type to the module.

Source

pub fn add_algebraic_type( &mut self, scope: impl IntoIterator<Item = RawIdentifier>, source_name: impl Into<RawIdentifier>, ty: AlgebraicType, custom_ordering: bool, ) -> AlgebraicTypeRef

Add a type to the typespace, along with a type alias declaring its name. This method should only be used for AlgebraicTypes not corresponding to a Rust type that implements SpacetimeType.

Returns a reference to the newly-added type.

NOT idempotent, calling this twice with the same name will cause errors during validation.

You must set custom_ordering if you’re not using the default element ordering.

Source

pub fn add_reducer( &mut self, source_name: impl Into<RawIdentifier>, params: ProductType, )

Add a reducer to the in-progress module. Accepts a ProductType of reducer arguments for convenience. The ProductType need not be registered in the typespace.

Importantly, if the reducer’s first argument is a ReducerContext, that information should not be provided to this method. That is an implementation detail handled by the module bindings and can be ignored. As far as the module definition is concerned, the reducer’s arguments start with the first non-ReducerContext argument.

(It is impossible, with the current implementation of ReducerContext, to have more than one ReducerContext argument, at least in Rust. This is because SpacetimeType is not implemented for ReducerContext, so it can never act like an ordinary argument.)

Source

pub fn add_procedure( &mut self, source_name: impl Into<RawIdentifier>, params: ProductType, return_type: AlgebraicType, )

Add a procedure to the in-progress module.

Accepts a ProductType of arguments. The arguments ProductType need not be registered in the typespace.

Also accepts an AlgebraicType return type. If this is a user-defined product or sum type, it should be registered in the typespace and indirected through an AlgebraicType::Ref.

The &mut ProcedureContext first argument to the procedure should not be included in the params.

Source

pub fn add_view( &mut self, source_name: impl Into<RawIdentifier>, index: usize, is_public: bool, is_anonymous: bool, params: ProductType, return_type: AlgebraicType, )

Add a view to the in-progress module.

Source

pub fn add_lifecycle_reducer( &mut self, lifecycle_spec: Lifecycle, function_name: impl Into<RawIdentifier>, params: ProductType, )

Add a lifecycle reducer assignment to the module.

The function must be a previously-added reducer.

Source

pub fn add_schedule( &mut self, table: impl Into<RawIdentifier>, column: impl Into<ColId>, function: impl Into<RawIdentifier>, )

Add a schedule definition to the module.

The function_name should name a reducer or procedure which accepts one argument, a row of the specified table.

The table must have the appropriate columns for a scheduled table.

Source

pub fn add_row_level_security(&mut self, sql: &str)

Add a row-level security policy to the module.

The sql expression should be a valid SQL expression that will be used to filter rows.

NOTE: The sql expression must be unique within the module.

Source

pub fn add_explicit_names(&mut self, names: ExplicitNames)

Source

pub fn set_case_conversion_policy(&mut self, policy: CaseConversionPolicy)

Set the case conversion policy for this module.

By default, SpacetimeDB applies SnakeCase conversion to table names, column names, reducer names, etc. Use CaseConversionPolicy::None to disable all case conversion (useful for modules with existing data that was stored under the original naming convention).

Source

pub fn finish(self) -> RawModuleDefV10

Finish building, consuming the builder and returning the module. The module should be validated before use.

Trait Implementations§

Source§

impl Default for RawModuleDefV10Builder

Source§

fn default() -> RawModuleDefV10Builder

Returns the “default value” for a type. Read more
Source§

impl TypespaceBuilder for RawModuleDefV10Builder

Implement TypespaceBuilder for V10

Source§

fn add( &mut self, typeid: TypeId, source_name: Option<&'static str>, make_ty: impl FnOnce(&mut Self) -> AlgebraicType, ) -> AlgebraicType

Returns and adds a representation of type T: 'static as an AlgebraicType with an optional name to the typing context in self.
Source§

fn add_type<T>(&mut self) -> AlgebraicType
where T: SpacetimeType, Self: Sized,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.