1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::stmt::{ExprArg, Source, SourceTableId, TableFactor};
use super::{TableRef, TableWithJoins};
/// A lowered table-level data source for a `SELECT` statement.
///
/// Contains a list of table references (which may be schema tables, CTEs, or
/// derived tables) and the `FROM` items that reference them by index
/// ([`SourceTableId`]).
///
/// # Examples
///
/// ```ignore
/// use toasty_core::stmt::{SourceTable, TableRef, TableWithJoins, TableFactor, SourceTableId};
/// use toasty_core::schema::db::TableId;
///
/// let source = SourceTable::new(
/// vec![TableRef::Table(TableId(0))],
/// TableWithJoins {
/// relation: TableFactor::Table(SourceTableId(0)),
/// joins: vec![],
/// },
/// );
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct SourceTable {
/// All table references used in this source. Indexed by [`SourceTableId`].
pub tables: Vec<TableRef>,
/// The `FROM` items, each being a table with optional joins.
pub from: Vec<TableWithJoins>,
}
impl SourceTable {
/// Creates a new `SourceTable` with a single `FROM` item.
pub fn new(tables: Vec<TableRef>, from: TableWithJoins) -> Self {
Self {
tables,
from: vec![from],
}
}
}
impl From<ExprArg> for SourceTable {
fn from(value: ExprArg) -> Self {
SourceTable {
tables: vec![TableRef::Arg(value)],
from: vec![TableWithJoins {
relation: TableFactor::Table(SourceTableId(0)),
joins: vec![],
}],
}
}
}
impl From<SourceTable> for Source {
fn from(value: SourceTable) -> Self {
Source::Table(value)
}
}