Cotton code
55 lines · 2.1 KB · RustRaw
//! The shapes the schema data is written in — `schema::table_specs` and//! `schema::fts` are the data, and these are their types.//!//! They were the shapes a generator emitted into, until step 5i deleted it and//! the data became ordinary source (R2). Nothing here carries behaviour.//! Changing a shape here changes the file format, so it travels with a//! `MIGRATIONS` entry and a new `schema_snapshot` fixture.//!//! There is no `Migration` shape, and there will not be one until there is a//! second Rust version to reach (spec R2/R3): a v45 file is ADOPTED in place,//! and `schema::ddl::SCHEMA_DDL` is the whole of what a file is built//! from./// `ColumnCodec` in tableSpecs.ts — how a column's value is stored and read.#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub enum Codec {    Text,    Int,    Real,    Bool,    Json,    MoneyMinor,    DecimalText,    Timestamp,}/// `TableSpec` in tableSpecs.ts.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct TableSpec {    pub name: &'static str,    /// Always a single column (synthetic where the natural key is composite).    pub pk: &'static str,    /// Every column with its codec, in declaration order.    pub columns: &'static [(&'static str, Codec)],    /// The composite natural key where `pk` is synthetic, else empty.    pub natural_key: &'static [&'static str],    /// The FTS5 table this row's text is mirrored into, if any.    pub fts_into: Option<&'static str>,}/// One entry of `FTS_SOURCES` in fts.ts. `columns[0]` is the title column.////// No `since`: every source exists in the file this schema was taken from, and/// "which version births this index" is a question only a file walking a/// ladder could ask.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct FtsSource {    pub fts: &'static str,    pub source: &'static str,    pub columns: &'static [&'static str],    /// The tokenizer the index is created with: words    /// ([`crate::schema::fts::WORDS`]) for every index but Chat's, which    /// matches any three characters in a row ([`crate::schema::fts::TRIGRAM`]).    pub tokenize: &'static str,}