Struct sea_query::index::IndexCreateStatement
source · [−]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")"#
);
Create index if not exists
use sea_query::{tests_cfg::*, *};
let index = Index::create()
.if_not_exists()
.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 IF NOT EXISTS "idx-glyph-aspect" ON "glyph" ("aspect")"#
);
assert_eq!(
index.to_string(SqliteQueryBuilder),
r#"CREATE INDEX IF NOT EXISTS "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
sourceimpl IndexCreateStatement
impl IndexCreateStatement
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new IndexCreateStatement
sourcepub fn if_not_exists(&mut self) -> &mut Self
pub fn if_not_exists(&mut self) -> &mut Self
Create index if index not exists
sourcepub fn col<C: 'static>(&mut self, col: C) -> &mut Selfwhere
C: IntoIndexColumn,
pub fn col<C: 'static>(&mut self, col: C) -> &mut Selfwhere
C: IntoIndexColumn,
Add index column
sourcepub fn full_text(&mut self) -> &mut Self
pub fn full_text(&mut self) -> &mut Self
Set index as full text.
On MySQL, this is FULLTEXT
.
On PgSQL, this is GIN
.
sourcepub fn index_type(&mut self, index_type: IndexType) -> &mut Self
pub fn index_type(&mut self, index_type: IndexType) -> &mut Self
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) -> Self
sourceimpl IndexCreateStatement
impl IndexCreateStatement
pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String
pub fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String
pub fn build_any(&self, schema_builder: &dyn SchemaBuilder) -> String
Trait Implementations
sourceimpl Clone for IndexCreateStatement
impl Clone for IndexCreateStatement
sourcefn clone(&self) -> IndexCreateStatement
fn clone(&self) -> IndexCreateStatement
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for IndexCreateStatement
impl Debug for IndexCreateStatement
sourceimpl Default for IndexCreateStatement
impl Default for IndexCreateStatement
sourceimpl SchemaStatementBuilder for IndexCreateStatement
impl SchemaStatementBuilder for IndexCreateStatement
sourcefn build<T: SchemaBuilder>(&self, schema_builder: T) -> String
fn build<T: SchemaBuilder>(&self, schema_builder: T) -> String
Build corresponding SQL statement for certain database backend and return SQL string
sourcefn 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
sourcefn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String
fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String
Build corresponding SQL statement for certain database backend and return SQL string
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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