pub struct Index {
pub id: IndexId,
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 },
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.
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.
Implementations§
Source§impl Index
impl Index
Sourcepub fn partition_fields(&self) -> &[IndexField]
pub fn partition_fields(&self) -> &[IndexField]
Returns the partition-scoped fields of this index.
Partition fields come before local fields and determine data distribution in NoSQL backends.
Sourcepub fn local_fields(&self) -> &[IndexField]
pub fn local_fields(&self) -> &[IndexField]
Returns the local (sort-key) fields of this index.
Local fields follow partition fields and determine ordering within a partition.