Skip to main content

wasm_dbms_api/
utils.rs

1use crate::prelude::{ColumnDef, Value, ValuesSource};
2
3/// Helper function which takes a list of `(ValuesSource, Value)` tuples, takes only those with
4/// [`ValuesSource::Foreign`] matching the provided table and column names, and returns a vector of
5/// the corresponding `Value`s with the [`ValuesSource`] set to [`ValuesSource::This`].
6pub fn self_reference_values(
7    values: &[(ValuesSource, Vec<(ColumnDef, Value)>)],
8    table: &'static str,
9    local_column: &'static str,
10) -> Vec<(ValuesSource, Vec<(ColumnDef, Value)>)> {
11    values
12        .iter()
13        .filter(|(source, _)| {
14            matches!(source, ValuesSource::Foreign { table: t, column } if t == table && column == local_column)
15        })
16        .map(|(_, value)| (ValuesSource::This, value.clone()))
17        .collect()
18}