Struct barrel::table::Table

source ·
pub struct Table {
    pub meta: TableMeta,
    /* private fields */
}

Fields§

§meta: TableMeta

Implementations§

source§

impl Table

source

pub fn new<S: Into<String>>(name: S) -> Self

source

pub fn add_column<S: Into<String>>(&mut self, name: S, _type: Type) -> &mut Type

Add a new column to a table

table.add_column("id", types::primary());
table.add_column("name", types::varchar(64));
source

pub fn drop_column<S: Into<String>>(&mut self, name: S)

source

pub fn rename_column<S: Into<String>>(&mut self, old: S, new: S)

source

pub fn inject_custom<S: Into<String>>(&mut self, sql: S)

Inject a line of custom SQL into the table block

This is a bypass to the barrel typesystem, in case there is something your database supports that barrel doesn’t, or if there is an issue with the way that barrel represents types. It does however mean that the SQL provided needs to be specific for one database, meaning that future migrations might become cumbersome.

source

pub fn add_index<S: Into<String>>(&mut self, name: S, columns: Type)

Add a new index to a table, spanning over multiple columns

source

pub fn add_constraint<S: Into<String>>(&mut self, name: S, columns: Type)

source

pub fn add_partial_index<S: Into<String>>( &mut self, name: S, columns: Type, conditions: S )

source

pub fn drop_index<S: Into<String>>(&mut self, name: S)

Drop an index on this table

source

pub fn add_foreign_key( &mut self, columns_on_this_side: &[&str], related_table: &str, columns_on_that_side: &[&str] )

source

pub fn set_primary_key(&mut self, columns: &[&str])

source

pub fn make<T: SqlGenerator>( &mut self, ex: bool, schema: Option<&str> ) -> SqlChanges

Generate Sql for this table.

Trait Implementations§

source§

impl Clone for Table

source§

fn clone(&self) -> Table

Returns a copy 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 Table

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Table

§

impl !Send for Table

§

impl !Sync for Table

§

impl Unpin for Table

§

impl !UnwindSafe for Table

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.