pub struct Schema {
pub tables: Vec<Table>,
pub pg: Vec<Table>,
}Expand description
Every table a program’s read model has.
Fields§
§tables: Vec<Table>The program’s own read models, in the public namespace — and Schema::CATALOGUE.
pg: Vec<Table>pg_catalog, in the pg_catalog namespace: the same schema under the names an outside
tool already knows (crate::pg).
A separate list rather than more entries in tables, because these describe the read
models and are not read models themselves: select * from beck_columns and
beck explain sql are about what the program holds, and a catalogue that listed itself
there would answer a question nobody asked.
Implementations§
Source§impl Schema
impl Schema
Sourcepub const CATALOGUE: &'static str = "beck_columns"
pub const CATALOGUE: &'static str = "beck_columns"
The name of the catalogue table, which says what a table is derived from — the question
pg_catalog has no column for, because PostgreSQL has no such thing to describe.
pub fn table(&self, name: &str) -> Option<&Table>
Sourcepub fn relation(
&self,
namespace: Option<&str>,
name: &str,
) -> Result<&Table, SqlError>
pub fn relation( &self, namespace: Option<&str>, name: &str, ) -> Result<&Table, SqlError>
A relation named by a from entry: a read model, or one of pg_catalog’s.
An unqualified name is a read model first, so a program with a table called pg_class
gets its own. A name qualified with pg_catalog is only ever the catalogue’s, and one
qualified with anything else is refused rather than searched for: two namespaces is all
there is, and a client that asked a third a question deserves to be told so.
Sourcepub fn builtin_rows(&self, t: &Table) -> Option<Vec<Value>>
pub fn builtin_rows(&self, t: &Table) -> Option<Vec<Value>>
The rows of a table this module builds rather than reads from a running program.
One place, so a scan and a join get the same rows: Rows::scan never sees one of these,
and a reader with no program behind it can still answer the catalogue.
Sourcepub fn catalogue_values(&self) -> Vec<Value>
pub fn catalogue_values(&self) -> Vec<Value>
The catalogue’s own rows as values, which is what a query that joins it reads.
It is built on demand: the catalogue is a handful of rows describing a schema that cannot change while a process is running, and a cache would be a second copy of it to keep true.