pub trait SchemaWithPK:
DynTable
+ Clone
+ Hash {
// Required methods
fn number_of_primary_keys(&self) -> usize;
fn primary_key_index(&self, col_idx: usize) -> Option<usize>;
fn extract_pk<S: Clone, B: Clone>(
&self,
values: &impl IndexableValues<Text = S, Binary = B>,
) -> Vec<Value<S, B>>;
// Provided method
fn primary_key_columns(&self) -> impl Iterator<Item = usize> { ... }
}Expand description
Extension trait for schemas with typed primary key extraction.
This trait is NOT object-safe due to the associated type.
Use DynTable with the extract_pk method for dynamic dispatch.
§Type Parameter
The PrimaryKeyValue type varies by schema:
- For
TableSchemaimplementors: derived from<PrimaryKey as NestedColumns>::NestedValues, e.g.,(i64,)or(i64, String) - For
Box<dyn DynTable>:Vec<Value>(runtime, unknown structure)
Required Methods§
Sourcefn number_of_primary_keys(&self) -> usize
fn number_of_primary_keys(&self) -> usize
Returns the number of primary key columns in the schema.
Sourcefn primary_key_index(&self, col_idx: usize) -> Option<usize>
fn primary_key_index(&self, col_idx: usize) -> Option<usize>
Returns the primary key index of the primary key by the column index.
Sourcefn extract_pk<S: Clone, B: Clone>(
&self,
values: &impl IndexableValues<Text = S, Binary = B>,
) -> Vec<Value<S, B>>
fn extract_pk<S: Clone, B: Clone>( &self, values: &impl IndexableValues<Text = S, Binary = B>, ) -> Vec<Value<S, B>>
Extract primary key values from a full row.
The values slice must have length equal to number_of_columns().
Returns the PK values in column order, typed appropriately.
§Panics
Panics if the values collection is shorter than the schema’s column count.
Provided Methods§
Sourcefn primary_key_columns(&self) -> impl Iterator<Item = usize>
fn primary_key_columns(&self) -> impl Iterator<Item = usize>
Returns the column indices of the primary key, ordered by their position within the composite key (key order).
This is the forward companion to primary_key_index:
that maps a column index to its key position, while this lists the key
column indices in key order. The ordering matches
extract_pk, so the two agree on which cell is which
key component.
The walk selects the column holding key position 0, then 1, up to the
key width, so it allocates nothing and costs O(k*n) for a key of width
k over n columns.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".