schema_core/config/
join.rs1use serde::{Deserialize, Serialize};
2
3use crate::{Field, common};
4
5use super::Filter;
6
7#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
12pub struct Join {
13 pub table: common::TableName,
14 pub kind: JoinKind,
15 pub primary_key: common::ColumnName,
16 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub filters: Option<Vec<Filter>>,
18 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub order_by: Option<Vec<OrderBy>>,
20 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub limit: Option<u64>,
22 pub fields: Vec<Field>,
23}
24
25#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
36#[serde(rename_all = "snake_case")]
37pub enum JoinKind {
38 BelongsTo { column: common::ColumnName },
39 HasOne { foreign_key: common::ColumnName },
40 HasMany { foreign_key: common::ColumnName },
41 ManyToMany { through: Through },
42}
43
44impl JoinKind {
45 pub fn is_to_many(&self) -> bool {
48 matches!(self, JoinKind::HasMany { .. } | JoinKind::ManyToMany { .. })
49 }
50}
51
52#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
57#[serde(rename_all = "snake_case")]
58pub enum AggregateKey {
59 Direct(common::ColumnName),
60 Through(Through),
61}
62
63#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
65pub struct Through {
66 pub table: common::TableName,
67 pub left_key: common::ColumnName,
68 pub right_key: common::ColumnName,
69}
70
71#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
72pub struct OrderBy {
73 pub column: common::ColumnName,
74 #[serde(default, skip_serializing_if = "Option::is_none")]
75 pub direction: Option<Direction>,
76}
77
78#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
79#[serde(rename_all = "snake_case")]
80pub enum Direction {
81 Asc,
82 Desc,
83}