Schema

Struct Schema 

Source
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

Source

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.

Source

pub fn table(&self, name: &str) -> Option<&Table>

Source

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.

Source

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.

Source

pub fn of(placed: &Placed, plan: &Plan) -> Schema

Derive the read model of a sliced program.

Source

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.

Source

pub fn ddl(&self) -> String

The schema as CREATE TABLE statements, for beck explain sql.

Nothing executes this — there is no database to execute it against, and saying so is the point. It is the shape a person needs in order to write the query they were going to write.

Source§

impl Schema

Source

pub fn run(&self, sql: &str, rows: &dyn Rows) -> Result<Answer, SqlError>

Parse and run one statement.

Source

pub fn describe(&self, sql: &str) -> Result<Vec<Column>, SqlError>

What a statement’s result looks like, without running it. Describe needs this before Execute has happened.

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Schema

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

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.