toasty_core/driver/operation/get_by_key.rs
1use super::Operation;
2
3use crate::{
4 schema::db::{ColumnId, TableId},
5 stmt,
6};
7
8/// Fetches one or more records by exact primary key match.
9///
10/// This is the key-value equivalent of `SELECT ... WHERE pk IN (...)`. The
11/// driver returns a row for each key that exists in the table.
12///
13/// # Examples
14///
15/// ```ignore
16/// use toasty_core::driver::operation::{GetByKey, Operation};
17///
18/// let op = GetByKey {
19/// table: table_id,
20/// select: vec![col_id_a, col_id_b],
21/// keys: vec![key1, key2],
22/// };
23/// let operation: Operation = op.into();
24/// ```
25#[derive(Debug, Clone)]
26pub struct GetByKey {
27 /// The table to fetch from.
28 pub table: TableId,
29
30 /// Which columns to include in the returned rows.
31 pub select: Vec<ColumnId>,
32
33 /// Primary key values identifying the records to fetch.
34 pub keys: Vec<stmt::Value>,
35}
36
37impl From<GetByKey> for Operation {
38 fn from(value: GetByKey) -> Self {
39 Self::GetByKey(value)
40 }
41}