Skip to main content

HasKey

Trait HasKey 

Source
pub trait HasKey {
    type Marker: Marker;
    type Key: Fetch + Bind + Tuple<Self::Marker>;

    const GET_BY_KEY: &'static str;
    const UPSERT: &'static str;
    const UPDATE: &'static str;
    const DELETE: &'static str;
    const KEY_VALUE: NestedValueDef;

    // Required methods
    fn get_key(&self) -> <Self::Key as Tuple<Self::Marker>>::Ref<'_>;
    fn get_key_mut(&mut self) -> <Self::Key as Tuple<Self::Marker>>::Mut<'_>;

    // Provided method
    fn make_ref(&self) -> Ref<Self>
       where Self::Key: CloneFromRef<Self::Marker> { ... }
}
Expand description

Table that has a primary key, which may be composite

Required Associated Constants§

Source

const GET_BY_KEY: &'static str

SELECT (...) WHERE (... = ?)

Select an entry by its primary key. Binds however many columns the key has.

Source

const UPSERT: &'static str

INSERT INTO ... VALUES ( ?, ...) ON CONFLICT DO UPDATE SET (x = excluded.x)*

*: Instead of DO UPDATE SET (…) it’s DO NOTHING for key-only tables.

Be aware that this doesn’t actually specify the “conflict target”, that is, on violation of which uniqueness constraint to DO UPDATE SET, it simply assumes it is because of the primary key, and it will only update the non-key columns to the excluded values. As such, you should probably not use this for tables with other UNIQUE constraints.
See https://sqlite.org/lang_upsert.html for more on the “upsert” statement, which is not standard SQL.

Source

const UPDATE: &'static str

UPDATE (...) SET (... = ?) WHERE (... = ?)

Update all the non-key values in the row WHERE the key matches.

Source

const DELETE: &'static str

Delete a row by its primary key.

Source

const KEY_VALUE: NestedValueDef

Definition of the key value (used by Ref)

Required Associated Types§

Source

type Marker: Marker

Marker type used to disambiguate bounds on the key

Source

type Key: Fetch + Bind + Tuple<Self::Marker>

Type of the key. If the key is composite, this will be a tuple.

Required Methods§

Source

fn get_key(&self) -> <Self::Key as Tuple<Self::Marker>>::Ref<'_>

Source

fn get_key_mut(&mut self) -> <Self::Key as Tuple<Self::Marker>>::Mut<'_>

Provided Methods§

Source

fn make_ref(&self) -> Ref<Self>
where Self::Key: CloneFromRef<Self::Marker>,

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§