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<Cols> CreateTableBuilder<NoName, Cols>
impl<Cols> CreateTableBuilder<NoName, Cols>
Source§impl<Name> CreateTableBuilder<Name, NoColumns>
impl<Name> CreateTableBuilder<Name, NoColumns>
Sourcepub fn column(
self,
column: ColumnDefinition,
) -> CreateTableBuilder<Name, HasColumns>
pub fn column( self, column: ColumnDefinition, ) -> CreateTableBuilder<Name, HasColumns>
Adds the first column to the table.
Source§impl<Name> CreateTableBuilder<Name, HasColumns>
impl<Name> CreateTableBuilder<Name, HasColumns>
Sourcepub fn column(self, column: ColumnDefinition) -> Self
pub fn column(self, column: ColumnDefinition) -> Self
Adds another column to the table.
Source§impl<Name, Cols> CreateTableBuilder<Name, Cols>
impl<Name, Cols> CreateTableBuilder<Name, Cols>
Sourcepub fn if_not_exists(self) -> Self
pub fn if_not_exists(self) -> Self
Uses IF NOT EXISTS clause.
Source§impl<Cols> CreateTableBuilder<HasName, Cols>
impl<Cols> CreateTableBuilder<HasName, Cols>
Sourcepub fn constraint(self, constraint: TableConstraint) -> Self
pub fn constraint(self, constraint: TableConstraint) -> Self
Adds a table-level constraint.
Sourcepub fn primary_key(self, columns: &[&str]) -> Self
pub fn primary_key(self, columns: &[&str]) -> Self
Adds a composite primary key constraint.
Sourcepub fn primary_key_named(
self,
name: impl Into<String>,
columns: &[&str],
) -> Self
pub fn primary_key_named( self, name: impl Into<String>, columns: &[&str], ) -> Self
Adds a named composite primary key constraint.
Sourcepub fn unique_constraint(self, columns: &[&str]) -> Self
pub fn unique_constraint(self, columns: &[&str]) -> Self
Adds a unique constraint on multiple columns.
Sourcepub fn unique_constraint_named(
self,
name: impl Into<String>,
columns: &[&str],
) -> Self
pub fn unique_constraint_named( self, name: impl Into<String>, columns: &[&str], ) -> Self
Adds a named unique constraint on multiple columns.
Sourcepub fn check_constraint(self, expression: impl Into<String>) -> Self
pub fn check_constraint(self, expression: impl Into<String>) -> Self
Adds a check constraint.
Source§impl CreateTableBuilder<HasName, HasColumns>
impl CreateTableBuilder<HasName, HasColumns>
Sourcepub fn build(self) -> CreateTableOp
pub fn build(self) -> CreateTableOp
Builds the CreateTableOp.
Trait Implementations§
Source§impl<Name: Clone, Cols: Clone> Clone for CreateTableBuilder<Name, Cols>
impl<Name: Clone, Cols: Clone> Clone for CreateTableBuilder<Name, Cols>
Source§fn clone(&self) -> CreateTableBuilder<Name, Cols>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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>
impl<Name, Cols> Sync for CreateTableBuilder<Name, Cols>
impl<Name, Cols> Unpin for CreateTableBuilder<Name, Cols>
impl<Name, Cols> UnwindSafe for CreateTableBuilder<Name, Cols>where
Name: UnwindSafe,
Cols: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more