pub struct IndexCreateStatement { /* private fields */ }
Expand description
Create an index for an existing table
Examples
use sea_query::{tests_cfg::*, *};
let index = Index::create()
.name("idx-glyph-aspect")
.table(Glyph::Table)
.col(Glyph::Aspect)
.to_owned();
assert_eq!(
index.to_string(MysqlQueryBuilder),
r#"CREATE INDEX `idx-glyph-aspect` ON `glyph` (`aspect`)"#
);
assert_eq!(
index.to_string(PostgresQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect")"#
);
assert_eq!(
index.to_string(SqliteQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect")"#
);
Index with prefix
use sea_query::{tests_cfg::*, *};
let index = Index::create()
.name("idx-glyph-aspect")
.table(Glyph::Table)
.col((Glyph::Aspect, 128))
.to_owned();
assert_eq!(
index.to_string(MysqlQueryBuilder),
r#"CREATE INDEX `idx-glyph-aspect` ON `glyph` (`aspect` (128))"#
);
assert_eq!(
index.to_string(PostgresQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect" (128))"#
);
assert_eq!(
index.to_string(SqliteQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect")"#
);
Index with order
use sea_query::{tests_cfg::*, *};
let index = Index::create()
.name("idx-glyph-aspect")
.table(Glyph::Table)
.col((Glyph::Aspect, IndexOrder::Desc))
.to_owned();
assert_eq!(
index.to_string(MysqlQueryBuilder),
r#"CREATE INDEX `idx-glyph-aspect` ON `glyph` (`aspect` DESC)"#
);
assert_eq!(
index.to_string(PostgresQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect" DESC)"#
);
assert_eq!(
index.to_string(SqliteQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect" DESC)"#
);
Index with prefix and order
use sea_query::{tests_cfg::*, *};
let index = Index::create()
.name("idx-glyph-aspect")
.table(Glyph::Table)
.col((Glyph::Aspect, 64, IndexOrder::Asc))
.to_owned();
assert_eq!(
index.to_string(MysqlQueryBuilder),
r#"CREATE INDEX `idx-glyph-aspect` ON `glyph` (`aspect` (64) ASC)"#
);
assert_eq!(
index.to_string(PostgresQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect" (64) ASC)"#
);
assert_eq!(
index.to_string(SqliteQueryBuilder),
r#"CREATE INDEX "idx-glyph-aspect" ON "glyph" ("aspect" ASC)"#
);
Implementations
impl IndexCreateStatement
impl IndexCreateStatement
pub fn new() -> IndexCreateStatement
pub fn new() -> IndexCreateStatement
Construct a new IndexCreateStatement
pub fn name(&mut self, name: &str) -> &mut IndexCreateStatement
pub fn name(&mut self, name: &str) -> &mut IndexCreateStatement
Set index name
pub fn table<T>(&mut self, table: T) -> &mut IndexCreateStatement where
T: 'static + Iden,
pub fn table<T>(&mut self, table: T) -> &mut IndexCreateStatement where
T: 'static + Iden,
Set target table
pub fn col<C>(&mut self, col: C) -> &mut IndexCreateStatement where
C: 'static + IntoIndexColumn,
pub fn col<C>(&mut self, col: C) -> &mut IndexCreateStatement where
C: 'static + IntoIndexColumn,
Add index column
pub fn primary(&mut self) -> &mut IndexCreateStatement
pub fn primary(&mut self) -> &mut IndexCreateStatement
Set index as primary
pub fn unique(&mut self) -> &mut IndexCreateStatement
pub fn unique(&mut self) -> &mut IndexCreateStatement
Set index as unique
pub fn full_text(&mut self) -> &mut IndexCreateStatement
pub fn full_text(&mut self) -> &mut IndexCreateStatement
Set index as full text.
On MySQL, this is FULLTEXT
.
On PgSQL, this is GIN
.
pub fn index_type(&mut self, index_type: IndexType) -> &mut IndexCreateStatement
pub fn index_type(&mut self, index_type: IndexType) -> &mut IndexCreateStatement
Set index type. Not available on Sqlite.
pub fn is_primary_key(&self) -> bool
pub fn is_unique_key(&self) -> bool
pub fn get_index_spec(&self) -> &TableIndex
pub fn take(&mut self) -> IndexCreateStatement
impl IndexCreateStatement
impl IndexCreateStatement
pub fn to_string<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
pub fn build<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
pub fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String
Trait Implementations
impl Clone for IndexCreateStatement
impl Clone for IndexCreateStatement
fn clone(&self) -> IndexCreateStatement
fn clone(&self) -> IndexCreateStatement
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for IndexCreateStatement
impl Debug for IndexCreateStatement
impl Default for IndexCreateStatement
impl Default for IndexCreateStatement
fn default() -> IndexCreateStatement
fn default() -> IndexCreateStatement
Returns the “default value” for a type. Read more
impl SchemaStatementBuilder for IndexCreateStatement
impl SchemaStatementBuilder for IndexCreateStatement
fn build<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
fn build<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
Build corresponding SQL statement for certain database backend and return SQL string
fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String
fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String
Build corresponding SQL statement for certain database backend and return SQL string
fn to_string<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
fn to_string<T>(&self, schema_builder: T) -> String where
T: SchemaBuilder,
Build corresponding SQL statement for certain database backend and return SQL string
sourceimpl StatementBuilder for IndexCreateStatement
impl StatementBuilder for IndexCreateStatement
sourcefn build(&self, db_backend: &DatabaseBackend) -> Statement
fn build(&self, db_backend: &DatabaseBackend) -> Statement
Method to call in order to build a Statement
Auto Trait Implementations
impl !RefUnwindSafe for IndexCreateStatement
impl Send for IndexCreateStatement
impl Sync for IndexCreateStatement
impl Unpin for IndexCreateStatement
impl !UnwindSafe for IndexCreateStatement
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more