Skip to main content

PhinxTable

Struct PhinxTable 

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

Phinx 风格表构建器

提供链式 API 构建 CREATE TABLE / ALTER TABLE 语句

Implementations§

Source§

impl PhinxTable

Source

pub fn new(table_name: impl Into<String>) -> Self

创建新的表构建器

Source

pub fn add_column<F>( self, name: impl Into<String>, col_type: ColumnType, options_fn: F, ) -> Self

添加列(Phinx addColumn 等价物)

§用法
PhinxTable::new("users")
    .add_column("name", ColumnType::String, |c| c.limit(255).not_null())
    .add_column("age", ColumnType::Integer, |_| {})
Source

pub fn add_index<F>(self, columns: &[&str], options_fn: F) -> Self

添加索引(Phinx addIndex 等价物)

Source

pub fn add_foreign_key<F>( self, column: impl Into<String>, referenced_table: impl Into<String>, referenced_column: impl Into<String>, options_fn: F, ) -> Self

添加外键(Phinx addForeignKey 等价物)

Source

pub fn set_primary_key(self, columns: Vec<String>) -> Self

设置主键(Phinx 风格,可复合主键)

Source

pub fn if_not_exists(self) -> Self

设置 IF NOT EXISTS

Source

pub fn create(&self, db_type: DbType) -> Result<String, DbError>

生成 CREATE TABLE SQL(Phinx create() 等价物)

Source

pub fn add_columns_sql(&self, db_type: DbType) -> String

生成 ALTER TABLE 添加列 SQL(Phinx change() 等价物的一部分)

Source

pub fn drop(&self) -> String

生成 DROP TABLE SQL(Phinx drop() 等价物)

Source

pub fn drop_column_sql(&self, column: &str) -> String

生成 DROP COLUMN SQL(Phinx removeColumn 等价物)

Source

pub fn rename_column_sql(&self, old_name: &str, new_name: &str) -> String

生成 RENAME COLUMN SQL(Phinx renameColumn 等价物)

Source

pub fn change_column_sql( &self, column: &str, new_type: ColumnType, db_type: DbType, ) -> String

生成 CHANGE COLUMN SQL(Phinx changeColumn 等价物)

Source

pub fn truncate_sql(&self) -> String

生成 TRUNCATE SQL(Phinx truncate() 等价物)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more