Skip to main content

SchemaWithPK

Trait SchemaWithPK 

Source
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) -> Vec<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 TableSchema implementors: derived from <PrimaryKey as NestedColumns>::NestedValues, e.g., (i64,) or (i64, String)
  • For Box<dyn DynTable>: Vec<Value> (runtime, unknown structure)

Required Methods§

Source

fn number_of_primary_keys(&self) -> usize

Returns the number of primary key columns in the schema.

Source

fn primary_key_index(&self, col_idx: usize) -> Option<usize>

Returns the primary key index of the primary key by the column index.

Source

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§

Source

fn primary_key_columns(&self) -> Vec<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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: SchemaWithPK> SchemaWithPK for &T

Source§

fn number_of_primary_keys(&self) -> usize

Source§

fn primary_key_index(&self, col_idx: usize) -> Option<usize>

Source§

fn extract_pk<S: Clone, B: Clone>( &self, values: &impl IndexableValues<Text = S, Binary = B>, ) -> Vec<Value<S, B>>

Implementors§