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§
Sourceconst GET_BY_KEY: &'static str
const GET_BY_KEY: &'static str
SELECT (...) WHERE (... = ?)
Select an entry by its primary key. Binds however many columns the key has.
Sourceconst UPSERT: &'static str
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.
Sourceconst UPDATE: &'static str
const UPDATE: &'static str
UPDATE (...) SET (... = ?) WHERE (... = ?)
Update all the non-key values in the row WHERE the key matches.
Sourceconst KEY_VALUE: NestedValueDef
const KEY_VALUE: NestedValueDef
Definition of the key value (used by Ref)
Required Associated Types§
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 Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".