Skip to main content

CreateTableBuilder

Struct CreateTableBuilder 

Source
pub struct CreateTableBuilder<Name, Cols> { /* private fields */ }
Expand description

Type-safe CREATE TABLE builder.

Uses the typestate pattern to ensure that:

  • A table name must be set before building
  • At least one column must be added before building

§Example

use oxide_sql_core::migrations::{CreateTableBuilder, bigint, varchar, timestamp};

let op = CreateTableBuilder::new()
    .name("users")
    .column(bigint("id").primary_key().autoincrement().build())
    .column(varchar("username", 255).not_null().unique().build())
    .column(timestamp("created_at").not_null().default_expr("CURRENT_TIMESTAMP").build())
    .build();

assert_eq!(op.name, "users");
assert_eq!(op.columns.len(), 3);

Implementations§

Source§

impl CreateTableBuilder<NoName, NoColumns>

Source

pub fn new() -> Self

Creates a new CreateTableBuilder.

Source§

impl<Cols> CreateTableBuilder<NoName, Cols>

Source

pub fn name(self, name: impl Into<String>) -> CreateTableBuilder<HasName, Cols>

Sets the table name.

Source§

impl<Name> CreateTableBuilder<Name, NoColumns>

Source

pub fn column( self, column: ColumnDefinition, ) -> CreateTableBuilder<Name, HasColumns>

Adds the first column to the table.

Source§

impl<Name> CreateTableBuilder<Name, HasColumns>

Source

pub fn column(self, column: ColumnDefinition) -> Self

Adds another column to the table.

Source§

impl<Name, Cols> CreateTableBuilder<Name, Cols>

Source

pub fn if_not_exists(self) -> Self

Uses IF NOT EXISTS clause.

Source§

impl<Cols> CreateTableBuilder<HasName, Cols>

Source

pub fn constraint(self, constraint: TableConstraint) -> Self

Adds a table-level constraint.

Source

pub fn primary_key(self, columns: &[&str]) -> Self

Adds a composite primary key constraint.

Source

pub fn primary_key_named( self, name: impl Into<String>, columns: &[&str], ) -> Self

Adds a named composite primary key constraint.

Source

pub fn unique_constraint(self, columns: &[&str]) -> Self

Adds a unique constraint on multiple columns.

Source

pub fn unique_constraint_named( self, name: impl Into<String>, columns: &[&str], ) -> Self

Adds a named unique constraint on multiple columns.

Source

pub fn check_constraint(self, expression: impl Into<String>) -> Self

Adds a check constraint.

Source

pub fn check_constraint_named( self, name: impl Into<String>, expression: impl Into<String>, ) -> Self

Adds a named check constraint.

Source§

impl CreateTableBuilder<HasName, HasColumns>

Source

pub fn build(self) -> CreateTableOp

Builds the CreateTableOp.

Trait Implementations§

Source§

impl<Name: Clone, Cols: Clone> Clone for CreateTableBuilder<Name, Cols>

Source§

fn clone(&self) -> CreateTableBuilder<Name, Cols>

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<Name: Debug, Cols: Debug> Debug for CreateTableBuilder<Name, Cols>

Source§

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

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

impl Default for CreateTableBuilder<NoName, NoColumns>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Name, Cols> Freeze for CreateTableBuilder<Name, Cols>

§

impl<Name, Cols> RefUnwindSafe for CreateTableBuilder<Name, Cols>
where Name: RefUnwindSafe, Cols: RefUnwindSafe,

§

impl<Name, Cols> Send for CreateTableBuilder<Name, Cols>
where Name: Send, Cols: Send,

§

impl<Name, Cols> Sync for CreateTableBuilder<Name, Cols>
where Name: Sync, Cols: Sync,

§

impl<Name, Cols> Unpin for CreateTableBuilder<Name, Cols>
where Name: Unpin, Cols: Unpin,

§

impl<Name, Cols> UnwindSafe for CreateTableBuilder<Name, Cols>
where Name: UnwindSafe, Cols: UnwindSafe,

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.