pub struct Schema {Show 17 fields
pub tables: FxHashMap<String, Arc<Table>>,
pub materialized_view_names: FxHashSet<String>,
pub materialized_view_sql: FxHashMap<String, String>,
pub incremental_views: FxHashMap<String, Arc<Mutex<IncrementalView>>>,
pub views: ViewsMap,
pub triggers: FxHashMap<String, VecDeque<Arc<Trigger>>>,
pub indexes: FxHashMap<String, VecDeque<Arc<Index>>>,
pub has_indexes: FxHashSet<String>,
pub schema_version: u32,
pub analyze_stats: AnalyzeStats,
pub table_to_materialized_views: FxHashMap<String, Vec<String>>,
pub incompatible_views: FxHashSet<String>,
pub broken_views: FxHashSet<String>,
pub dropped_root_pages: FxHashSet<i64>,
pub type_registry: FxHashMap<String, Arc<TypeDef>>,
pub generated_columns_enabled: bool,
pub sequences: FxHashMap<String, Arc<Sequence>>,
/* private fields */
}Fields§
§tables: FxHashMap<String, Arc<Table>>§materialized_view_names: FxHashSet<String>Track which tables are actually materialized views
materialized_view_sql: FxHashMap<String, String>Store original SQL for materialized views (for .schema command)
incremental_views: FxHashMap<String, Arc<Mutex<IncrementalView>>>The incremental view objects (DBSP circuits)
views: ViewsMap§triggers: FxHashMap<String, VecDeque<Arc<Trigger>>>table_name to list of triggers
indexes: FxHashMap<String, VecDeque<Arc<Index>>>table_name to list of indexes for the table
has_indexes: FxHashSet<String>§schema_version: u32§analyze_stats: AnalyzeStatsStatistics collected via ANALYZE for regular B-tree tables and indexes.
table_to_materialized_views: FxHashMap<String, Vec<String>>Mapping from table names to the materialized views that depend on them
incompatible_views: FxHashSet<String>Track views that exist but have incompatible versions
broken_views: FxHashSet<String>View rows in sqlite_schema whose stored SQL failed to parse (e.g. older versions wrote view column lists without identifier quoting). The rows are tolerated at load time so the database stays usable; tracking the names lets DROP VIEW remove them.
dropped_root_pages: FxHashSet<i64>Root pages of tables/indexes that have been dropped but not yet checkpointed. In MVCC mode, when a table is dropped, the btree pages are not freed until checkpoint. integrity_check needs to know about these pages to avoid false positives about “page never used”.
type_registry: FxHashMap<String, Arc<TypeDef>>Custom type registry, loaded from sqlite_turso_types
generated_columns_enabled: bool§sequences: FxHashMap<String, Arc<Sequence>>Named sequences (CREATE SEQUENCE)
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a schema with custom types enabled.
Panics if a hardcoded built-in type definition is malformed (programmer
bug). Production code that opens user databases should prefer
Schema::with_options which returns Result.
pub fn with_options(enable_custom_types: bool) -> Result<Self>
Sourcepub fn register_internal_vtab<T>(&mut self, table: T) -> Result<String>where
T: InternalVirtualTable + 'static,
pub fn register_internal_vtab<T>(&mut self, table: T) -> Result<String>where
T: InternalVirtualTable + 'static,
Add an InternalVirtualTable to the schema’s catalog. The wrapped
table appears under the name returned by its name() method and is
queryable like any other table. Returns the name actually inserted.
Intended for callers that want to surface state as a queryable table
without going through CREATE VIRTUAL TABLE — for example, extensions
that contribute metadata tables or alternative-dialect catalogs.
Sourcepub fn get_type_def(
&self,
type_name: &str,
is_strict: bool,
) -> Option<&Arc<TypeDef>>
pub fn get_type_def( &self, type_name: &str, is_strict: bool, ) -> Option<&Arc<TypeDef>>
Look up a custom type definition by name.
Custom types are only valid on STRICT tables; pass is_strict from the
owning table so that non-STRICT tables never resolve a custom type.
Sourcepub fn get_type_def_unchecked(&self, type_name: &str) -> Option<&Arc<TypeDef>>
pub fn get_type_def_unchecked(&self, type_name: &str) -> Option<&Arc<TypeDef>>
Look up a custom type definition by name without a strictness check. Only use this for operations that aren’t column-scoped (e.g. DROP TYPE, CREATE TABLE validation, CAST).
Sourcepub fn resolve_type(
&self,
type_name: &str,
is_strict: bool,
) -> Result<Option<ResolvedType>>
pub fn resolve_type( &self, type_name: &str, is_strict: bool, ) -> Result<Option<ResolvedType>>
Resolve a custom type fully: look it up (with strictness gate) and chase
the base-type chain to the ultimate primitive.
Returns Ok(None) if the type is not registered (or the table isn’t strict).
Sourcepub fn resolve_type_unchecked(
&self,
type_name: &str,
) -> Result<Option<ResolvedType>>
pub fn resolve_type_unchecked( &self, type_name: &str, ) -> Result<Option<ResolvedType>>
Resolve a custom type fully without a strictness check.
Returns Ok(None) if the type is not in the registry.
pub fn remove_type(&mut self, type_name: &str)
Sourcepub fn resolve_base_type_chain(
&self,
type_name: &str,
) -> Result<(String, Vec<Arc<TypeDef>>)>
pub fn resolve_base_type_chain( &self, type_name: &str, ) -> Result<(String, Vec<Arc<TypeDef>>)>
Chase the base type chain: domain_a → domain_b → integer Returns (ultimate_primitive, ordered_chain_of_TypeDefs) The chain is ordered from child to ancestor. Errors on cycles or missing intermediate types.
Sourcepub fn add_type_from_sql(&mut self, sql: &str) -> Result<()>
pub fn add_type_from_sql(&mut self, sql: &str) -> Result<()>
Parse a CREATE TYPE SQL string and add the type to the in-memory registry.
Sourcepub fn load_type_definitions(&mut self, type_sqls: &[String]) -> Result<()>
pub fn load_type_definitions(&mut self, type_sqls: &[String]) -> Result<()>
Load type definitions from CREATE TYPE SQL strings and resolve custom type affinities on all STRICT tables. This is the shared entry point used by both initial database open and schema reparse.
Sourcepub fn resolve_all_custom_type_affinities(&mut self) -> Result<()>
pub fn resolve_all_custom_type_affinities(&mut self) -> Result<()>
Resolve custom type affinities for all STRICT tables in the schema. Call this after loading user-defined types from __turso_internal_types so that columns declared with custom types use the BASE type’s affinity.
pub fn is_unique_idx_name(&self, name: &str) -> bool
pub fn add_materialized_view( &mut self, view: IncrementalView, table: Arc<Table>, sql: String, )
pub fn get_materialized_view( &self, name: &str, ) -> Option<Arc<Mutex<IncrementalView>>>
Sourcepub fn has_compatible_dbsp_state_table(&self, view_name: &str) -> bool
pub fn has_compatible_dbsp_state_table(&self, view_name: &str) -> bool
Check if DBSP state table exists with the current version
pub fn is_materialized_view(&self, name: &str) -> bool
Sourcepub fn with_incompatible_dependent_views<F, T>(
&self,
table_name: &str,
f: F,
) -> T
pub fn with_incompatible_dependent_views<F, T>( &self, table_name: &str, f: F, ) -> T
Apply a function to a table’s incompatible dependent materialized views
pub fn remove_view(&mut self, name: &str) -> Result<()>
Sourcepub fn add_materialized_view_dependency(
&mut self,
table_name: &str,
view_name: &str,
)
pub fn add_materialized_view_dependency( &mut self, table_name: &str, view_name: &str, )
Register that a materialized view depends on a table
Sourcepub fn get_dependent_materialized_views(&self, table_name: &str) -> Vec<String>
pub fn get_dependent_materialized_views(&self, table_name: &str) -> Vec<String>
Get all materialized views that depend on a given table
pub fn add_trigger(&mut self, trigger: Trigger, table_name: &str) -> Result<()>
pub fn remove_trigger(&mut self, name: &str) -> Result<()>
pub fn remove_triggers_for_table(&mut self, table_name: &str)
Sourcepub fn remove_triggers_for_table_with_db(
&mut self,
table_name: &str,
target_db: usize,
)
pub fn remove_triggers_for_table_with_db( &mut self, table_name: &str, target_db: usize, )
Like [remove_triggers_for_table] but only removes triggers whose
target_database_id matches target_db (or is None, meaning
“targets the parent schema’s table of this name”, which also
applies). Used from DROP TABLE main.t to clean up temp triggers
without accidentally removing ones that target temp.t or
aux.t (the plain remove_triggers_for_table keys only on
table name).
pub fn get_trigger_for_table( &self, table_name: &str, name: &str, ) -> Option<Arc<Trigger>>
pub fn get_triggers_for_table( &self, table_name: &str, ) -> impl Iterator<Item = &Arc<Trigger>> + Clone
pub fn get_trigger(&self, name: &str) -> Option<Arc<Trigger>>
pub fn add_btree_table(&mut self, table: Arc<BTreeTable>) -> Result<()>
pub fn add_virtual_table(&mut self, table: Arc<VirtualTable>) -> Result<()>
pub fn get_table(&self, name: &str) -> Option<Arc<Table>>
pub fn table_name_for_root_page(&self, root_page: i64) -> Option<&str>
pub fn remove_table(&mut self, table_name: &str)
pub fn register_table_root_page(&mut self, name: &str, table: &Table)
pub fn unregister_table_root_page(&mut self, table: &Table)
pub fn get_btree_table(&self, name: &str) -> Option<Arc<BTreeTable>>
pub fn add_index(&mut self, index: Arc<Index>) -> Result<()>
pub fn get_indices(&self, table_name: &str) -> impl Iterator<Item = &Arc<Index>>
pub fn get_index( &self, table_name: &str, index_name: &str, ) -> Option<&Arc<Index>>
pub fn remove_indices_for_table(&mut self, table_name: &str)
pub fn remove_index(&mut self, idx: &Index)
pub fn table_has_indexes(&self, table_name: &str) -> bool
pub fn table_set_has_index(&mut self, table_name: &str)
Sourcepub fn make_from_btree(
&mut self,
state: &mut MakeFromBtreeState,
mv_cursor: Option<Arc<RwLock<MvccLazyCursor<MvccClock, DynAllocator>>>>,
pager: &Arc<Pager>,
syms: &SymbolTable,
) -> Result<IOResult<()>>
pub fn make_from_btree( &mut self, state: &mut MakeFromBtreeState, mv_cursor: Option<Arc<RwLock<MvccLazyCursor<MvccClock, DynAllocator>>>>, pager: &Arc<Pager>, syms: &SymbolTable, ) -> Result<IOResult<()>>
Update Schema by scanning the first root page (sqlite_schema) Returns Result<IOResult<()>> to allow async operation with external IO loop
Sourcepub fn populate_indices(
&mut self,
syms: &SymbolTable,
from_sql_indexes: Vec<UnparsedFromSqlIndex>,
automatic_indices: HashMap<String, Vec<(String, i64)>>,
mvcc_enabled: bool,
) -> Result<()>
pub fn populate_indices( &mut self, syms: &SymbolTable, from_sql_indexes: Vec<UnparsedFromSqlIndex>, automatic_indices: HashMap<String, Vec<(String, i64)>>, mvcc_enabled: bool, ) -> Result<()>
Populate indices parsed from the schema. from_sql_indexes: indices explicitly created with CREATE INDEX automatic_indices: indices created automatically for primary key and unique constraints
Sourcepub fn populate_materialized_views(
&mut self,
materialized_view_info: HashMap<String, (String, i64)>,
dbsp_state_roots: HashMap<String, i64>,
dbsp_state_index_roots: HashMap<String, i64>,
) -> Result<()>
pub fn populate_materialized_views( &mut self, materialized_view_info: HashMap<String, (String, i64)>, dbsp_state_roots: HashMap<String, i64>, dbsp_state_index_roots: HashMap<String, i64>, ) -> Result<()>
Populate materialized views parsed from the schema.
Sourcepub fn sequence_backing_table_names(&self) -> Vec<(String, String)>
pub fn sequence_backing_table_names(&self) -> Vec<(String, String)>
Yield (backing_table_name, sequence_name) for every backing table
currently in the schema. Shared shape for the SQL-based descriptor
loader in Connection so the prefix-strip lives in one place.
pub fn handle_schema_row( &mut self, ty: &str, name: &str, table_name: &str, root_page: i64, maybe_sql: Option<&str>, syms: &SymbolTable, from_sql_indexes: &mut Vec<UnparsedFromSqlIndex>, automatic_indices: &mut HashMap<String, Vec<(String, i64)>>, dbsp_state_roots: &mut HashMap<String, i64>, dbsp_state_index_roots: &mut HashMap<String, i64>, materialized_view_info: &mut HashMap<String, (String, i64)>, resolve_attached_db: &dyn Fn(&str) -> Option<usize>, ) -> Result<()>
Sourcepub fn resolved_fks_referencing(
&self,
table_name: &str,
) -> Result<Vec<ResolvedFkRef>>
pub fn resolved_fks_referencing( &self, table_name: &str, ) -> Result<Vec<ResolvedFkRef>>
Compute all resolved FKs referencing table_name (arg: table_name is the parent).
Each item contains the child table, normalized columns/positions, and the parent lookup
strategy (rowid vs. UNIQUE index or PK).
Sourcepub fn resolved_fks_for_child(
&self,
child_table: &str,
) -> Result<Vec<ResolvedFkRef>>
pub fn resolved_fks_for_child( &self, child_table: &str, ) -> Result<Vec<ResolvedFkRef>>
Compute all resolved FKs declared by child_table.
Unlike resolved_fks_referencing, this requires every non-rowid parent key
to be backed by a non-partial UNIQUE index on exactly those columns.
Sourcepub fn any_resolved_fks_referencing(&self, table_name: &str) -> bool
pub fn any_resolved_fks_referencing(&self, table_name: &str) -> bool
Returns if any table declares a FOREIGN KEY whose parent is table_name.
Sourcepub fn has_child_fks(&self, table_name: &str) -> bool
pub fn has_child_fks(&self, table_name: &str) -> bool
Returns true if table_name declares any FOREIGN KEYs
pub fn get_sequence(&self, name: &str) -> Option<&Arc<Sequence>>
Sourcepub fn remove_sequence(&mut self, name: &str)
pub fn remove_sequence(&mut self, name: &str)
Remove a sequence and its backing table from the in-memory schema.
Sourcepub fn get_object_type(&self, name: &str) -> Option<SchemaObjectType>
pub fn get_object_type(&self, name: &str) -> Option<SchemaObjectType>
Returns the type of schema object with the given name, if one exists. Checks tables, views, and indexes.
Trait Implementations§
Source§impl TryClone for Schema
impl TryClone for Schema
Source§type Error = TryReserveError
type Error = TryReserveError
Copying a Schema requires deep cloning of all internal tables and indexes, even though they are wrapped in Arc.
Simply copying the Arc pointers would result in multiple Schema instances sharing the same underlying tables and indexes,
which could lead to panics or data races if any instance attempts to modify them.
To ensure each Schema is independent and safe to modify, we clone the underlying data for all tables and indexes.
fn try_clone(&self) -> Result<Self, Self::Error>
Auto Trait Implementations§
impl !RefUnwindSafe for Schema
impl !UnwindSafe for Schema
impl Freeze for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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