Skip to main content

Table

Struct Table 

Source
pub struct Table<'r, T> { /* private fields */ }
Expand description

A table: its queries, and its rows’ inserts and upserts. Derefs to the query of all its rows.

Implementations§

Source§

impl<'r, T> Table<'r, T>

Source

pub fn name(&self) -> &str

Source§

impl<T: Serialize + DeserializeOwned> Table<'_, T>

Source

pub fn insert(&self, row: &T) -> Result<T>

Inserts a row, every field it has, and gives it back as the file keeps it: the defaults and the generated columns the database filled.

Source

pub fn insert_all(&self, rows: &[T]) -> Result<Vec<T>>

Inserts rows of one shape as one write, all of them or none.

Source

pub fn upsert(&self, row: &T, upsert: Upsert) -> Result<Option<T>>

Inserts a row, or, when its key is taken, sets the columns update names on the row that holds it, if that row meets the upsert’s condition; None when the condition kept it.

Methods from Deref<Target = Query<'r, T>>§

Source

pub fn filter(&self, condition: impl Into<Sql>) -> Self

Adds a condition with and: a piece from sql!, sql::eq, sql::or and the rest. filter, since where is Rust’s own word.

Source

pub fn select<S>(&self, columns: impl Into<Sql>) -> Query<'r, S>

The columns a row holds, as SQL text, and the shape of the row they make.

Source

pub fn include<C>(&self, name: &str, query: &Query<'_, C>) -> Self

Gives each row the rows of another query as a list under name, a field of the row’s type, from the same statement: the query names the row it belongs to in its filter, by this table’s alias, names its columns with select, and has a limit, which counts for each row. Every value comes back as it is kept.

let latest = db
    .table::<Post>("posts as p")
    .select::<Post>("p.id, p.title")
    .filter("p.author_id = u.id")
    .order_by("p.id", Direction::Desc)
    .limit(3);
let authors: Vec<Author> = db.table::<Author>("users as u").include("posts", &latest).all()?;
Source

pub fn join(&self, table: &str, on: impl Into<Sql>) -> Self

Joins a table, "users as u", on a condition.

Source

pub fn left_join(&self, table: &str, on: impl Into<Sql>) -> Self

Joins a table whose columns may be null where no row of it meets the condition.

Source

pub fn group_by<I: IntoIterator<Item = S>, S: AsRef<str>>( &self, columns: I, ) -> Self

Groups the rows by columns, quoted as names.

Source

pub fn having(&self, condition: impl Into<Sql>) -> Self

A condition on the groups, as filter takes one.

Source

pub fn order_by(&self, column: &str, direction: Direction) -> Self

Orders the rows by a column, quoted as a name, so that a sort a request chooses cannot be SQL.

Source

pub fn order_by_sql(&self, piece: impl Into<Sql>, direction: Direction) -> Self

Orders the rows by a piece of SQL: sql!("lower(title)").

Source

pub fn limit(&self, rows: u64) -> Self

Source

pub fn offset(&self, rows: u64) -> Self

Source

pub fn to_sql(&self) -> Result<Sql>

The text and the values the query sends, to read or to log.

Source

pub fn count(&self) -> Result<u64>

How many rows the conditions match, or how many groups with group_by, without the order and the limit.

Source

pub fn explain(&self) -> Result<Vec<String>>

SQLite’s plan for the query, a line a step.

Source

pub fn update<I, S>(&self, sets: I) -> Result<Done>
where I: IntoIterator<Item = (S, Sql)>, S: AsRef<str>,

Sets columns of the rows the conditions match, each a value from sql::value or a piece of SQL, and says how many changed.

Source

pub fn delete(&self) -> Result<Done>

Deletes the rows the conditions match, and says how many it deleted.

Source

pub fn all(&self) -> Result<Vec<T>>

Source

pub fn one(&self) -> Result<Option<T>>

Source

pub fn scalar<V: DeserializeOwned>(&self) -> Result<V>

Source

pub fn list(&self, limit: u64, after: Option<&str>) -> Result<Page<T>>

A page after the last row of the one before, by the query’s order, which ends in a unique column so that no row is read twice or skipped; next reads the next page, and only of this query.

Trait Implementations§

Source§

impl<'r, T: Clone> Clone for Table<'r, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'r, T: Debug> Debug for Table<'r, T>

Source§

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

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

impl<'r, T> Deref for Table<'r, T>

Source§

type Target = Query<'r, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Query<'r, T>

Dereferences the value.

Auto Trait Implementations§

§

impl<'r, T> !RefUnwindSafe for Table<'r, T>

§

impl<'r, T> !Send for Table<'r, T>

§

impl<'r, T> !Sync for Table<'r, T>

§

impl<'r, T> !UnwindSafe for Table<'r, T>

§

impl<'r, T> Freeze for Table<'r, T>
where Query<'r, T>: Freeze,

§

impl<'r, T> Unpin for Table<'r, T>
where Query<'r, T>: Unpin,

§

impl<'r, T> UnsafeUnpin for Table<'r, T>
where Query<'r, T>: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more