Skip to main content

AlterTableStatement

Struct AlterTableStatement 

Source
pub struct AlterTableStatement { /* private fields */ }
Expand description

ALTER TABLE statement builder

This struct provides a fluent API for constructing ALTER TABLE queries.

§Examples

use reinhardt_query::prelude::*;
use reinhardt_query::types::ddl::{ColumnDef, ColumnType};

let query = Query::alter_table()
    .table("users")
    .add_column(
        ColumnDef::new("age")
            .column_type(ColumnType::Integer)
    );

Implementations§

Source§

impl AlterTableStatement

Source

pub fn new() -> Self

Create a new ALTER TABLE statement

Source

pub fn take(&mut self) -> Self

Take the ownership of data in the current AlterTableStatement

Source

pub fn table<T>(&mut self, tbl: T) -> &mut Self
where T: IntoTableRef,

Set the table to alter

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users");
Source

pub fn add_column(&mut self, column: ColumnDef) -> &mut Self

Add a column

§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::ddl::{ColumnDef, ColumnType};

let query = Query::alter_table()
    .table("users")
    .add_column(
        ColumnDef::new("age")
            .column_type(ColumnType::Integer)
            .not_null(false)
    );
Source

pub fn drop_column<C>(&mut self, column: C) -> &mut Self
where C: IntoIden,

Drop a column

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .drop_column("age");
Source

pub fn drop_column_if_exists<C>(&mut self, column: C) -> &mut Self
where C: IntoIden,

Drop a column with IF EXISTS

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .drop_column_if_exists("age");
Source

pub fn rename_column<C1, C2>(&mut self, old: C1, new: C2) -> &mut Self
where C1: IntoIden, C2: IntoIden,

Rename a column

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .rename_column("old_name", "new_name");
Source

pub fn modify_column(&mut self, column: ColumnDef) -> &mut Self

Modify a column (type or constraints)

§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::ddl::{ColumnDef, ColumnType};

let query = Query::alter_table()
    .table("users")
    .modify_column(
        ColumnDef::new("age")
            .column_type(ColumnType::BigInteger)
    );
Source

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

Add a constraint

§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::ddl::TableConstraint;

let query = Query::alter_table()
    .table("users")
    .add_constraint(TableConstraint::Unique {
        name: Some("uq_email".into()),
        columns: vec!["email".into()],
    });
Source

pub fn drop_constraint<C>(&mut self, constraint: C) -> &mut Self
where C: IntoIden,

Drop a constraint

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .drop_constraint("uq_email");
Source

pub fn drop_constraint_if_exists<C>(&mut self, constraint: C) -> &mut Self
where C: IntoIden,

Drop a constraint with IF EXISTS

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .drop_constraint_if_exists("uq_email");
Source

pub fn rename_table<T>(&mut self, new_name: T) -> &mut Self
where T: IntoIden,

Rename table

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .rename_table("accounts");
Source

pub fn add_primary_key<I, C>(&mut self, columns: I) -> &mut Self
where I: IntoIterator<Item = C>, C: IntoIden,

Add a primary key constraint

This is a convenience method for adding a PRIMARY KEY constraint.

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .add_primary_key(vec!["id"]);
Source

pub fn add_unique<I, C>(&mut self, columns: I) -> &mut Self
where I: IntoIterator<Item = C>, C: IntoIden,

Add a unique constraint

This is a convenience method for adding a UNIQUE constraint.

§Examples
use reinhardt_query::prelude::*;

let query = Query::alter_table()
    .table("users")
    .add_unique(vec!["email"]);
Source

pub fn add_foreign_key<I1, C1, T, I2, C2>( &mut self, columns: I1, ref_table: T, ref_columns: I2, on_delete: Option<ForeignKeyAction>, on_update: Option<ForeignKeyAction>, ) -> &mut Self
where I1: IntoIterator<Item = C1>, C1: IntoIden, T: IntoTableRef, I2: IntoIterator<Item = C2>, C2: IntoIden,

Add a foreign key constraint

This is a convenience method for adding a FOREIGN KEY constraint.

§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::ddl::ForeignKeyAction;

let query = Query::alter_table()
    .table("posts")
    .add_foreign_key(
        vec!["user_id"],
        "users",
        vec!["id"],
        Some(ForeignKeyAction::Cascade),
        None,
    );

Trait Implementations§

Source§

impl Clone for AlterTableStatement

Source§

fn clone(&self) -> AlterTableStatement

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 Debug for AlterTableStatement

Source§

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

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

impl Default for AlterTableStatement

Source§

fn default() -> Self

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

impl QueryStatementBuilder for AlterTableStatement

Source§

fn build_any(&self, query_builder: &dyn QueryBuilderTrait) -> (String, Values)

Build SQL statement for a database backend and collect query parameters Read more
Source§

fn to_string<T: QueryBuilderTrait>(&self, query_builder: T) -> String

Build SQL statement for a database backend and return SQL string with values inlined as SQL literals. Read more
Source§

fn build<T: QueryBuilderTrait>(&self, query_builder: T) -> (String, Values)

Build SQL statement with parameter collection Read more
Source§

impl QueryStatementWriter for AlterTableStatement

Auto Trait Implementations§

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.