Struct barrel::types::Type

source ·
pub struct Type {
    pub nullable: bool,
    pub unique: bool,
    pub increments: bool,
    pub indexed: bool,
    pub primary: bool,
    pub default: Option<WrappedDefault<'static>>,
    pub size: Option<usize>,
    pub inner: BaseType,
}
Expand description

A database column type and all the metadata attached to it

Using this struct directly is not recommended. Instead, you should be using the constructor APIs in the types module.

A Type is an enum provided to other barrel APIs in order to generate SQL datatypes. Working with them directly is possible but not recommended.

Instead, you can use these helper functions to construct Type enums of different…types and constraints. Field metadata is added via chainable factory pattern functions.

Default values

If no additional arguments are provided, some assumptions will be made about the metadata of a column type.

  • nullable: false
  • indexed: false
  • unique: false
  • default: None
  • size: None (which will error if size is important)

Examples

extern crate barrel;
use barrel::types::*;

// Make your own Primary key :)
let col = integer().increments(true).unique(true);

Fields§

§nullable: bool§unique: bool§increments: bool§indexed: bool§primary: bool§default: Option<WrappedDefault<'static>>§size: Option<usize>§inner: BaseType

Implementations§

source§

impl Type

This is a public API, be considered about breaking thigns

source

pub fn nullable(self, arg: bool) -> Self

Set the nullability of this type

source

pub fn unique(self, arg: bool) -> Self

Set the uniqueness of this type

source

pub fn increments(self, arg: bool) -> Self

Specify if this type should auto-increment

source

pub fn indexed(self, arg: bool) -> Self

Specify if this type should be indexed by your SQL implementation

source

pub fn primary(self, arg: bool) -> Self

Specify if this type should be a primary key

source

pub fn default(self, arg: impl Into<WrappedDefault<'static>>) -> Self

Provide a default value for a type column

source

pub fn size(self, arg: usize) -> Self

Specify a size limit (important or varchar & similar)

Trait Implementations§

source§

impl Clone for Type

source§

fn clone(&self) -> Type

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 Type

source§

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

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

impl PartialEq for Type

source§

fn eq(&self, other: &Type) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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.