pub struct Index {
pub id: IndexId,
pub name: Option<String>,
pub fields: Vec<IndexField>,
pub unique: bool,
pub primary_key: bool,
}Expand description
An index defined on a model’s fields.
Indices speed up queries by letting the database locate rows without a full table scan. An index can cover one or more fields, may enforce uniqueness, and may serve as the primary key.
Fields are split into partition fields (used for distribution in NoSQL backends like DynamoDB) and local fields (sort keys or secondary columns).
§Examples
use toasty_core::schema::app::{Index, IndexId, IndexField, ModelId};
use toasty_core::schema::db::{IndexOp, IndexScope};
let index = Index {
id: IndexId { model: ModelId(0), index: 0 },
name: None,
fields: vec![IndexField {
field: ModelId(0).field(0),
op: IndexOp::Eq,
scope: IndexScope::Local,
}],
unique: true,
primary_key: true,
};
assert!(index.unique);
assert!(index.primary_key);Fields§
§id: IndexIdUniquely identifies this index within the schema.
name: Option<String>User-provided index name from #[index(name = "...", ...)] or
#[key(name = "...", ...)]. When None, the schema builder generates
a name automatically.
fields: Vec<IndexField>Fields included in the index, in order.
unique: boolWhen true, the index enforces uniqueness across indexed entries.
primary_key: boolWhen true, this index represents the model’s primary key.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Index
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnsafeUnpin for Index
impl UnwindSafe for Index
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