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)]
20 pub nullable: bool,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
22 pub filters: Option<Vec<Filter>>,
23 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub order_by: Option<Vec<OrderBy>>,
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub limit: Option<u64>,
27 pub fields: Vec<Field>,
28}
29
30#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub enum JoinKind {
43 BelongsTo { column: common::ColumnName },
44 HasOne { foreign_key: common::ColumnName },
45 HasMany { foreign_key: common::ColumnName },
46 ManyToMany { through: Through },
47}
48
49impl JoinKind {
50 pub fn is_to_many(&self) -> bool {
53 matches!(self, JoinKind::HasMany { .. } | JoinKind::ManyToMany { .. })
54 }
55}
56
57#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
62#[serde(rename_all = "snake_case")]
63pub enum AggregateKey {
64 Direct(common::ColumnName),
65 Through(Through),
66}
67
68#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
70pub struct Through {
71 pub table: common::TableName,
72 pub left_key: common::ColumnName,
73 pub right_key: common::ColumnName,
74}
75
76#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
77pub struct OrderBy {
78 pub column: common::ColumnName,
79 #[serde(default, skip_serializing_if = "Option::is_none")]
80 pub direction: Option<Direction>,
81}
82
83#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
84#[serde(rename_all = "snake_case")]
85pub enum Direction {
86 Asc,
87 Desc,
88}