Skip to content
Closed
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
1 change: 1 addition & 0 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub use sats::SpacetimeType;
pub use spacetimedb_bindings_macro::__TableHelper;
pub use spacetimedb_bindings_sys as sys;
pub use spacetimedb_lib;
pub use spacetimedb_lib::db::raw_def::v10::CaseConversionPolicy;
pub use spacetimedb_lib::de::{Deserialize, DeserializeOwned};
pub use spacetimedb_lib::sats;
pub use spacetimedb_lib::ser::Serialize;
Expand Down
26 changes: 25 additions & 1 deletion crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::query_builder::{FromWhere, HasCols, LeftSemiJoin, RawQuery, RightSemi
use crate::table::IndexAlgo;
use crate::{sys, AnonymousViewContext, IterBuf, ReducerContext, ReducerResult, SpacetimeType, Table, ViewContext};
use spacetimedb_lib::bsatn::EncodeError;
use spacetimedb_lib::db::raw_def::v10::{ExplicitNames as RawExplicitNames, RawModuleDefV10Builder};
use spacetimedb_lib::db::raw_def::v10::{
CaseConversionPolicy, ExplicitNames as RawExplicitNames, RawModuleDefV10Builder,
};
pub use spacetimedb_lib::db::raw_def::v9::Lifecycle as LifecycleReducer;
use spacetimedb_lib::db::raw_def::v9::{RawIndexAlgorithm, TableType, ViewResultHeader};
use spacetimedb_lib::de::{self, Deserialize, DeserializeOwned, Error as _, SeqProductAccess};
Expand Down Expand Up @@ -856,6 +858,28 @@ pub fn register_row_level_security(sql: &'static str) {
})
}

/// Set the case conversion policy for this module.
///
/// This is an internal API for modules that need to opt out of the default
/// `SnakeCase` case conversion (e.g. controldb which has existing data).
///
/// # Usage
///
/// ```ignore
/// #[export_name = "__preinit__10_no_case_conversion"]
/// extern "C" fn no_case_conversion() {
/// spacetimedb::rt::register_case_conversion_policy(
/// spacetimedb::rt::CaseConversionPolicy::None,
/// );
/// }
/// ```
#[doc(hidden)]
pub fn register_case_conversion_policy(policy: CaseConversionPolicy) {
register_describer(move |module| {
module.inner.set_case_conversion_policy(policy);
})
}

/// A builder for a module.
#[derive(Default)]
pub struct ModuleBuilder {
Expand Down
16 changes: 16 additions & 0 deletions crates/lib/src/db/raw_def/v10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,22 @@ impl RawModuleDefV10Builder {
self.explicit_names_mut().merge(names);
}

/// 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).
pub fn set_case_conversion_policy(&mut self, policy: CaseConversionPolicy) {
// Remove any existing policy section.
self.module
.sections
.retain(|s| !matches!(s, RawModuleDefV10Section::CaseConversionPolicy(_)));
self.module
.sections
.push(RawModuleDefV10Section::CaseConversionPolicy(policy));
}

/// Finish building, consuming the builder and returning the module.
/// The module should be validated before use.
pub fn finish(self) -> RawModuleDefV10 {
Expand Down
Loading