Skip to main content

vantage_table/traits/
table_source.rs

1use std::hash::Hash;
2use std::pin::Pin;
3
4use async_trait::async_trait;
5use futures_core::Stream;
6use indexmap::IndexMap;
7use vantage_dataset::traits::Result;
8use vantage_expressions::{
9    Expression, Expressive,
10    traits::associated_expressions::AssociatedExpression,
11    traits::datasource::{DataSource, ExprDataSource, SelectableDataSource},
12    traits::expressive::ExpressiveEnum,
13};
14use vantage_types::{Entity, Record};
15use vantage_vista::Transaction;
16
17use crate::{
18    column::core::ColumnType,
19    source::SelectSeed,
20    table::{RollupOp, Table},
21    traits::column_like::ColumnLike,
22};
23
24/// A declared column whose type disagrees with the type the database
25/// itself declares for the stored field. A diagnostic for whoever edits the
26/// table's config: writes never depend on it.
27#[derive(Debug, Clone, PartialEq, Eq)]
28#[non_exhaustive]
29pub struct SchemaMismatch {
30    pub table: String,
31    pub column: String,
32    /// The column's type as declared (`timestamp`, `references: client`).
33    pub declared: String,
34    /// The stored field's type as the database prints it.
35    pub stored: String,
36    /// What to change to make them agree.
37    pub hint: String,
38}
39
40impl SchemaMismatch {
41    pub fn new(
42        table: impl Into<String>,
43        column: impl Into<String>,
44        declared: impl Into<String>,
45        stored: impl Into<String>,
46        hint: impl Into<String>,
47    ) -> Self {
48        Self {
49            table: table.into(),
50            column: column.into(),
51            declared: declared.into(),
52            stored: stored.into(),
53            hint: hint.into(),
54        }
55    }
56}
57
58/// A data source that holds tables: it names their column, value, id,
59/// source and condition types, and runs `Table`'s reads and writes.
60#[async_trait]
61pub trait TableSource: DataSource + Clone + 'static {
62    type Column<Type>: ColumnLike<Type> + Clone
63    where
64        Type: ColumnType;
65    type AnyType: ColumnType;
66    type Value: Clone + Send + Sync + 'static;
67    type Id: Send + Sync + Clone + Hash + Eq + 'static;
68
69    /// How this backend names its source. Most backends use `String`;
70    /// SQL/SurrealDB backends use `SelectSource<Self::Select>` so a table can
71    /// be sourced from an arbitrary sub-`SELECT`. See [`crate::source`].
72    type Source: crate::traits::table_source_spec::TableSourceSpec;
73
74    /// The condition type stored by `Table`. SQL/SurrealDB backends use
75    /// `Expression<Self::Value>`; document-oriented backends like MongoDB
76    /// can use a native filter type (e.g. `bson::Document`).
77    type Condition: Clone + Send + Sync + 'static;
78
79    /// Build a textual `field == value` condition.
80    ///
81    /// Generic UIs (e.g. CLI argument parsers) only have strings on
82    /// hand, so they need a way to construct a `Self::Condition` without
83    /// knowing the backend's native expression type. Backends that
84    /// don't support raw text filtering can leave the default, which
85    /// returns an error.
86    fn eq_condition(field: &str, value: &str) -> Result<Self::Condition> {
87        let _ = (field, value);
88        Err(vantage_core::error!(
89            "eq_condition not implemented for this TableSource"
90        ))
91    }
92
93    /// Build a `field == value` condition with a typed `Self::Value`.
94    ///
95    /// Sibling of [`TableSource::eq_condition`] for the case where the caller already
96    /// has a native-typed value in hand (e.g. `Reference::resolve_from_row`
97    /// pulling a join value out of a `Record<Self::Value>`). Avoids going
98    /// through string serialization and avoids the `Expression → T::Condition`
99    /// coercion that some document backends only support via a panic stub.
100    ///
101    /// Backends that participate in row-based reference traversal override;
102    /// the default returns an error so existing impls compile.
103    fn eq_value_condition(&self, field: &str, value: Self::Value) -> Result<Self::Condition> {
104        let _ = (field, value);
105        Err(vantage_core::error!(
106            "eq_value_condition not implemented for this TableSource"
107        ))
108    }
109
110    /// Build a `field IN (values)` condition from native-typed values: the
111    /// list-valued sibling of [`Self::eq_value_condition`].
112    /// [`Self::condition_column`] names `field` for it. An empty `values`
113    /// matches no row. The default returns an error.
114    fn in_values_condition(
115        &self,
116        field: &str,
117        values: Vec<Self::Value>,
118    ) -> Result<Self::Condition> {
119        let _ = (field, values);
120        Err(vantage_core::error!(
121            "in_values_condition not implemented for this TableSource"
122        ))
123    }
124
125    /// When `condition` is a literal `column = value`, return the pair.
126    ///
127    /// [`Table::add_condition`] registers it as a set invariant: an insert or
128    /// replace through the table fills an absent column, a patch may not change
129    /// it. Expression backends use [`crate::conditions::literal_equality`];
130    /// document backends read their own filter shape. Default `None`: the
131    /// condition still narrows, it just fills nothing.
132    fn condition_equality(&self, condition: &Self::Condition) -> Option<(String, Self::Value)> {
133        let _ = condition;
134        None
135    }
136
137    /// `condition` as text for people, e.g. `client_id = 7`: what a log entry
138    /// records for a bulk delete. Not for parsing; use
139    /// [`Self::condition_column`] / [`Self::condition_equality`] in code.
140    /// A part resolved only at query time renders as a placeholder.
141    fn describe_condition(&self, condition: &Self::Condition) -> String {
142        let _ = condition;
143        "<condition>".to_string()
144    }
145
146    /// The column `condition` narrows to values, for the shapes this backend
147    /// can read (`col = v`, `col IN (…)`, comparisons, `LIKE`), with a value
148    /// — not a column or an arbitrary expression — on the right. `None` when
149    /// it can't tell — a raw expression, a combination, a negation (`!=`,
150    /// `NOT IN`, `NOT LIKE`), `col = other_col` — so a check that requires a
151    /// condition on some column fails safe.
152    fn condition_column(&self, condition: &Self::Condition) -> Option<String> {
153        let _ = condition;
154        None
155    }
156
157    /// Whether every by-id write (`insert_table_value`, `replace_table_value`,
158    /// `patch_table_value`, `delete_table_value`, `insert_table_return_id_value`)
159    /// honours the write contract over `table.conditions()`: it only touches
160    /// rows in the set, and only leaves rows that still belong to it. A source
161    /// that returns `false` is refused any by-id write through a conditioned
162    /// table: `Table` refuses it with `Unsupported` before reaching the source.
163    /// Default `false`.
164    fn can_confine_writes(&self) -> bool {
165        false
166    }
167
168    /// Coerce a reference join value into the backend's native id form.
169    ///
170    /// Reference traversal (`resolve_from_row`) reads the join value raw out
171    /// of the parent row and uses it for both the narrowing eq-condition and
172    /// the target's insert invariant. On scalar-FK backends any value compares
173    /// as-is, so the default is identity. Backends with a richer id type
174    /// override: SurrealDB re-tags a `"table:key"` string — a record id that
175    /// round-tripped through JSON or a script — back into a record id, so the
176    /// condition renders a record literal (and an inserted child stores a
177    /// link), not a quoted string that matches nothing.
178    fn coerce_reference_value(&self, value: Self::Value) -> Self::Value {
179        value
180    }
181
182    /// `value` as this backend stores `column` of `table`: typed by the
183    /// column's declared type through the backend's type system, a has-one
184    /// key column as the backend's link, null as the type's "no value".
185    ///
186    /// `Table` calls it on every insert, replace and patch, for each key that
187    /// is a declared column other than the id: after the Normalize and
188    /// Populate hooks and the computed-column stripping, before the Validate
189    /// hooks and the set's invariants. So values a hook sets are typed too,
190    /// and invariants compare typed values. A missing key is never passed.
191    ///
192    /// A value that doesn't fit fails with
193    /// [`ErrorKind::InvalidValue`](vantage_core::ErrorKind::InvalidValue)
194    /// naming the column and the value. Must be idempotent: a value read
195    /// from the store and written back comes out unchanged. Default:
196    /// identity.
197    fn coerce_column_value<E>(
198        &self,
199        table: &Table<Self, E>,
200        column: &str,
201        value: Self::Value,
202    ) -> Result<Self::Value>
203    where
204        E: Entity<Self::Value>,
205        Self: Sized,
206    {
207        let _ = (table, column);
208        Ok(value)
209    }
210
211    /// The transaction this datasource runs its statements on, when it is
212    /// in transaction mode. Default `None`.
213    fn transaction(&self) -> Option<Transaction> {
214        None
215    }
216
217    /// This datasource back on its pool, for work that runs after the
218    /// transaction it was in. Default: a clone.
219    fn without_transaction(&self) -> Self {
220        self.clone()
221    }
222
223    /// Create a new column with the given name
224    fn create_column<Type: ColumnType>(&self, name: &str) -> Self::Column<Type>;
225
226    /// Convert a typed column to type-erased column
227    fn to_any_column<Type: ColumnType>(
228        &self,
229        column: Self::Column<Type>,
230    ) -> Self::Column<Self::AnyType>;
231
232    /// Attempt to convert a type-erased column back to typed column
233    fn convert_any_column<Type: ColumnType>(
234        &self,
235        any_column: Self::Column<Self::AnyType>,
236    ) -> Option<Self::Column<Type>>;
237
238    /// Create an expression from a template and parameters, similar to Expression::new
239    fn expr(
240        &self,
241        template: impl Into<String>,
242        parameters: Vec<ExpressiveEnum<Self::Value>>,
243    ) -> Expression<Self::Value>;
244
245    /// Create a search condition matching `search_value` across the columns
246    /// of [`Table::search_columns`]: those flagged `Searchable`, or every
247    /// column when none is. A backend may leave out columns it can't filter
248    /// on (dotted paths, imported columns). This is a *server-side*
249    /// capability — it pushes the match down to the backend's query engine.
250    ///
251    /// Different vendors implement search differently:
252    /// - SQL: `field LIKE '%value%'` (returns Expression)
253    /// - SurrealDB: `field CONTAINS 'value'` (returns Expression)
254    /// - MongoDB: `{ field: { $regex: 'value' } }` (returns MongoCondition)
255    ///
256    /// **Contract for backends that cannot search server-side** (e.g. CSV, redb):
257    /// return a condition that yields an `ErrorKind::Unsupported` error when it is
258    /// *resolved* — never a silent match-all (which leaks every row as if filtered)
259    /// and never a panic. Searching loaded/in-memory data is the Lens/Diorama
260    /// layer's responsibility, not the backend's.
261    fn search_table_condition<E>(
262        &self,
263        table: &Table<Self, E>,
264        search_value: &str,
265    ) -> Self::Condition
266    where
267        E: Entity<Self::Value>,
268        Self: Sized;
269
270    /// Get all data from a table as Record values with IDs (for ReadableValueSet implementation)
271    async fn list_table_values<E>(
272        &self,
273        table: &Table<Self, E>,
274    ) -> Result<IndexMap<Self::Id, Record<Self::Value>>>
275    where
276        E: Entity<Self::Value>,
277        Self: Sized;
278
279    /// Get a single record by ID as Record value (for ReadableValueSet implementation).
280    ///
281    /// Returns `Ok(None)` when no record exists with the given ID.
282    async fn get_table_value<E>(
283        &self,
284        table: &Table<Self, E>,
285        id: &Self::Id,
286    ) -> Result<Option<Record<Self::Value>>>
287    where
288        E: Entity<Self::Value>,
289        Self: Sized;
290
291    /// Get some data from a table as Record value with ID (for ReadableValueSet implementation)
292    async fn get_table_some_value<E>(
293        &self,
294        table: &Table<Self, E>,
295    ) -> Result<Option<(Self::Id, Record<Self::Value>)>>
296    where
297        E: Entity<Self::Value>,
298        Self: Sized;
299
300    /// Get count of records in the table
301    async fn get_table_count<E>(&self, table: &Table<Self, E>) -> Result<i64>
302    where
303        E: Entity<Self::Value>,
304        Self: Sized;
305
306    /// Get sum of a column in the table (returns native value type)
307    async fn get_table_sum<E>(
308        &self,
309        table: &Table<Self, E>,
310        column: &Self::Column<Self::AnyType>,
311    ) -> Result<Self::Value>
312    where
313        E: Entity<Self::Value>,
314        Self: Sized;
315
316    /// Get maximum value of a column in the table (returns native value type)
317    async fn get_table_max<E>(
318        &self,
319        table: &Table<Self, E>,
320        column: &Self::Column<Self::AnyType>,
321    ) -> Result<Self::Value>
322    where
323        E: Entity<Self::Value>,
324        Self: Sized;
325
326    /// Get minimum value of a column in the table (returns native value type)
327    async fn get_table_min<E>(
328        &self,
329        table: &Table<Self, E>,
330        column: &Self::Column<Self::AnyType>,
331    ) -> Result<Self::Value>
332    where
333        E: Entity<Self::Value>,
334        Self: Sized;
335
336    /// Insert a record by ID. **Confined and idempotent:** when the id is
337    /// already stored in `table.conditions()`, return the stored row unchanged;
338    /// when it is held by a row outside the set, fail with `Conflict`; a new
339    /// row must fit the conditions, else `Conflict` and nothing is stored.
340    /// Refuse with `Unsupported` when a condition can be neither applied nor
341    /// evaluated. See `WritableValueSet` for the table.
342    async fn insert_table_value<E>(
343        &self,
344        table: &Table<Self, E>,
345        id: &Self::Id,
346        record: &Record<Self::Value>,
347    ) -> Result<Record<Self::Value>>
348    where
349        E: Entity<Self::Value>,
350        Self: Sized;
351
352    /// Replace a record by ID, creating it when missing. **Confined and
353    /// idempotent:** an id held by a row outside `table.conditions()` fails
354    /// with `Conflict`; the written row must fit the conditions, else
355    /// `Conflict` and nothing changes. Refuse with `Unsupported` when a
356    /// condition can be neither applied nor evaluated. Write only the row with
357    /// this id: a clash on another UNIQUE column must surface as an error, so
358    /// no statement that updates or deletes the clashing row (`INSERT OR
359    /// REPLACE`, MySQL `ON DUPLICATE KEY UPDATE`). See `WritableValueSet` for
360    /// the table.
361    async fn replace_table_value<E>(
362        &self,
363        table: &Table<Self, E>,
364        id: &Self::Id,
365        record: &Record<Self::Value>,
366    ) -> Result<Record<Self::Value>>
367    where
368        E: Entity<Self::Value>,
369        Self: Sized;
370
371    /// Merge `partial` into the row with this ID. **Confined:** a missing row
372    /// or one outside `table.conditions()` is `NotFound` (marked); the merged
373    /// row must still fit the conditions, else `Conflict` and nothing changes.
374    /// Refuse with `Unsupported` when a condition can be neither applied nor
375    /// evaluated. See `WritableValueSet` for the table.
376    async fn patch_table_value<E>(
377        &self,
378        table: &Table<Self, E>,
379        id: &Self::Id,
380        partial: &Record<Self::Value>,
381    ) -> Result<Record<Self::Value>>
382    where
383        E: Entity<Self::Value>,
384        Self: Sized;
385
386    /// Delete a record by ID. **Confined and idempotent:** delete only when the
387    /// row is in `table.conditions()`; a missing row or a row outside the set
388    /// is `Ok(())` (no lookup is needed — SQL: `DELETE … WHERE id = ? AND
389    /// <conditions>`). Refuse with `Unsupported` when a condition can be
390    /// neither applied nor evaluated. See `WritableValueSet` for the table.
391    async fn delete_table_value<E>(&self, table: &Table<Self, E>, id: &Self::Id) -> Result<()>
392    where
393        E: Entity<Self::Value>,
394        Self: Sized;
395
396    /// Delete every record the table represents (for WritableValueSet).
397    ///
398    /// **Honour `table.conditions()`.** A conditioned table is a SUBSET, and
399    /// every read path already treats it as one, so deleting it must delete
400    /// that subset. An implementation that builds its statement from
401    /// `table_name()` alone silently truncates the table instead — the caller
402    /// narrowed to one row, and lost all of them. An unconditioned table
403    /// still deletes everything, which is the only case this looks like.
404    async fn delete_table_all_values<E>(&self, table: &Table<Self, E>) -> Result<()>
405    where
406        E: Entity<Self::Value>,
407        Self: Sized;
408
409    /// Insert a record under a generated ID and return it. **Confined, not
410    /// retry-safe:** the record must fit `table.conditions()`, else `Conflict`
411    /// and nothing is stored; a retry after a lost reply stores a second row.
412    /// Refuse with `Unsupported` when a condition can be neither applied nor
413    /// evaluated.
414    async fn insert_table_return_id_value<E>(
415        &self,
416        table: &Table<Self, E>,
417        record: &Record<Self::Value>,
418    ) -> Result<Self::Id>
419    where
420        E: Entity<Self::Value>,
421        Self: Sized;
422
423    /// Stream all records from a table as (Id, Record) pairs.
424    ///
425    /// Default implementation wraps `list_table_values` into a stream.
426    /// Backends with native streaming (e.g. REST APIs with pagination)
427    /// can override this to yield records incrementally.
428    #[allow(clippy::type_complexity)]
429    fn stream_table_values<'a, E>(
430        &'a self,
431        table: &Table<Self, E>,
432    ) -> Pin<Box<dyn Stream<Item = Result<(Self::Id, Record<Self::Value>)>> + Send + 'a>>
433    where
434        E: Entity<Self::Value> + 'a,
435        Self: Sized,
436    {
437        let table = table.clone();
438        Box::pin(async_stream::stream! {
439            let records = self.list_table_values(&table).await;
440            match records {
441                Ok(map) => {
442                    for item in map {
443                        yield Ok(item);
444                    }
445                }
446                Err(e) => yield Err(e),
447            }
448        })
449    }
450
451    /// Build a condition for "target_field IN (values of source_column from source_table)".
452    ///
453    /// Used by the relationship traversal system (`get_ref_as`) to filter
454    /// a target table by foreign key values from a source table.
455    ///
456    /// Each backend implements this natively:
457    /// - SQL backends build a subquery: `"id" IN (SELECT "bakery_id" FROM "client" WHERE ...)`
458    /// - MongoDB builds a deferred `{ field: { "$in": [...] } }` document
459    /// - CSV fetches values in memory and builds an IN condition
460    fn related_in_condition<SourceE: Entity<Self::Value> + 'static>(
461        &self,
462        target_field: &str,
463        source_table: &Table<Self, SourceE>,
464        source_column: &str,
465    ) -> Self::Condition
466    where
467        Self: Sized;
468
469    /// Build a correlated condition: `target_table.target_field = source_table.source_column`.
470    ///
471    /// Used by `get_subquery_as` / `get_subquery_erased` for embedding correlated
472    /// subqueries inside SELECT expressions (e.g.
473    /// `(SELECT COUNT(*) FROM order WHERE order.client_id = client.id)`), and by
474    /// the generic implicit-reference lowering. SQL and SurrealDB backends
475    /// produce table-qualified equality; backends without correlated subqueries
476    /// leave the default (which panics — they must also keep
477    /// [`supports_traversal`](Self::supports_traversal) `false`).
478    ///
479    /// Callers in this crate go through
480    /// [`try_related_correlated_condition`](Self::try_related_correlated_condition),
481    /// whose default reaches this one when `supports_traversal` is `true`.
482    fn related_correlated_condition(
483        &self,
484        target_table: &str,
485        target_field: &str,
486        source_table: &str,
487        source_column: &str,
488    ) -> Self::Condition {
489        let _ = (target_table, target_field, source_table, source_column);
490        unimplemented!("correlated subqueries not supported by this backend")
491    }
492
493    /// Fallible [`related_correlated_condition`](Self::related_correlated_condition),
494    /// used by `get_subquery_as` / `get_subquery_erased` and so by roll-ups.
495    ///
496    /// The default calls `related_correlated_condition` on a backend that
497    /// [`supports_traversal`](Self::supports_traversal) (which must override
498    /// it), so a driver overriding only that one keeps working. Any other
499    /// backend gets an `Unsupported` error at build time instead of a panic.
500    /// A backend that traverses some other way (MongoDB's `$lookup`) overrides
501    /// this one to refuse.
502    fn try_related_correlated_condition(
503        &self,
504        target_table: &str,
505        target_field: &str,
506        source_table: &str,
507        source_column: &str,
508    ) -> Result<Self::Condition> {
509        if self.supports_traversal() {
510            return Ok(self.related_correlated_condition(
511                target_table,
512                target_field,
513                source_table,
514                source_column,
515            ));
516        }
517        Err(
518            vantage_core::error!("correlated subqueries aren't supported by this backend")
519                .mark_unsupported(),
520        )
521    }
522
523    /// The expression of roll-up column `name`: `op` over `column` of the
524    /// rows `relation` (a has_many) gives for each `parent` row, narrowed by
525    /// `condition`. The callback [`Table::with_rollup`] stores calls it each
526    /// time a query that includes the column is built, so this is where the
527    /// relation's target is built and checked ([`Table::rollup_target`]).
528    ///
529    /// The default is a correlated subquery built from
530    /// [`Table::correlate_ref_target`] and [`Table::aggregate_query`]:
531    /// `(SELECT SUM("net") FROM "line" WHERE "line"."invoice" = "invoice"."id")`.
532    /// Over the parent's own table the child is read under an alias:
533    /// `(SELECT COUNT(*) FROM "employee" AS "employee_rollup" WHERE
534    /// "employee_rollup"."manager_id" = "employee"."id")`.
535    /// A backend overrides it to render something better, or to refuse with an
536    /// error.
537    fn rollup_expression<E>(
538        &self,
539        parent: &Table<Self, E>,
540        name: &str,
541        relation: &str,
542        op: RollupOp,
543        column: Option<&str>,
544        condition: Option<Self::Condition>,
545    ) -> Result<Expression<Self::Value>>
546    where
547        E: Entity<Self::Value> + 'static,
548        Self: SelectableDataSource<Self::Value, Self::Condition> + Sized,
549        Self::Source: SelectSeed<
550                <Self as SelectableDataSource<Self::Value, Self::Condition>>::Select,
551                Self::Value,
552                Self::Condition,
553            >,
554        <Self as SelectableDataSource<Self::Value, Self::Condition>>::Select:
555            Expressive<Self::Value>,
556        Self::Value: From<String>,
557        Self::Column<Self::AnyType>: Expressive<Self::Value>,
558    {
559        let target = parent.rollup_target(name, relation, column)?;
560        // Unaliased, `child.fk = parent.id` over the parent's own table reads
561        // the inner row on both sides and counts the wrong rows.
562        let alias = (target.table_name() == parent.table_name())
563            .then(|| format!("{}_rollup", parent.table_name()));
564        let mut child = parent.correlate_ref_target(relation, target, alias.as_deref())?;
565        if let Some(condition) = condition {
566            child.add_condition(condition);
567        }
568        child.aggregate_query(op, column)
569    }
570
571    /// Whether this backend can lower a dotted active column
572    /// (`"country.name"`) into its own query — a nested correlated subquery for
573    /// SQL, a native idiom path for SurrealDB, `$lookup` stages for MongoDB.
574    /// Backends that can build none of these (e.g. CSV, REST) leave the
575    /// default `false`, and
576    /// [`Table::with_active_columns`](crate::table::Table::with_active_columns)
577    /// rejects dotted names against them at build time rather than at fetch time.
578    fn supports_traversal(&self) -> bool {
579        false
580    }
581
582    /// Build a backend-native path expression for a dotted active column,
583    /// tried before the generic correlated-subquery chain.
584    ///
585    /// `hops` holds each traversed relation's **foreign-key/link field** (not
586    /// its registry name — a relation named `owner` over a link field `client`
587    /// must lower to `client.…`), and `column` the final field. The default
588    /// returns `None`, so backends fall back to the generic chain built on
589    /// [`related_correlated_condition`](Self::related_correlated_condition).
590    /// SurrealDB overrides this to emit an idiom path (`batch.golf_course.name`,
591    /// each segment escaped separately); multi-hop comes for free. The returned
592    /// expression is unaliased — `select()` aliases it to the dotted name.
593    fn traversal_path_expr(&self, hops: &[&str], column: &str) -> Option<Expression<Self::Value>> {
594        let _ = (hops, column);
595        None
596    }
597
598    /// Return an associated expression that, when resolved, yields all values
599    /// of the given typed column from this table (respecting current conditions).
600    ///
601    /// For query-language backends, this can be a subquery expression.
602    /// For simple backends (CSV), this uses a `DeferredFn` that loads data
603    /// and extracts the column values at execution time.
604    ///
605    /// The returned `AssociatedExpression` can be:
606    /// - Executed directly: `.get().await -> Result<Vec<Type>>`
607    /// - Composed into expressions: used via `Expressive` trait in `in_()` conditions
608    ///
609    /// ```rust,ignore
610    /// let fk_col = source.get_column::<String>("bakery_id").unwrap();
611    /// let fk_values = source.data_source().column_table_values_expr(&source, &fk_col);
612    /// // Execute: let ids = fk_values.get().await?;
613    /// // Or compose: target.add_condition(target["id"].in_((fk_values)));
614    /// ```
615    fn column_table_values_expr<'a, E, Type: ColumnType>(
616        &'a self,
617        table: &Table<Self, E>,
618        column: &Self::Column<Type>,
619    ) -> AssociatedExpression<'a, Self, Self::Value, Vec<Type>>
620    where
621        E: Entity<Self::Value> + 'static,
622        Self: ExprDataSource<Self::Value> + Sized;
623}