1#![allow(dead_code)]
3
4use std::ops::Range;
5
6pub type Span = Range<usize>;
7
8#[derive(Debug, Clone)]
9pub struct Document {
10 pub items: Vec<DocumentItem>,
11 pub span: Span,
12}
13
14#[derive(Debug, Clone)]
15pub enum DocumentItem {
16 Table(Table),
17 Ref(Ref),
18 Enum(Enum),
19 Project(Project),
20}
21
22#[derive(Debug, Clone)]
23pub struct Ident {
24 pub name: String,
25 pub span: Span,
26}
27
28#[derive(Debug, Clone)]
29pub struct Table {
30 pub name: Ident,
31 pub schema: Option<Ident>,
32 pub alias: Option<Ident>,
33 pub items: Vec<TableItem>,
34 pub settings: Vec<TableSetting>,
35 pub span: Span,
36}
37
38#[derive(Debug, Clone)]
39pub enum TableItem {
40 Column(Column),
41 Indexes(IndexesBlock),
42 Note(StringLiteral),
43}
44
45#[derive(Debug, Clone)]
46pub struct Column {
47 pub name: Ident,
48 pub col_type: String,
49 pub settings: Vec<ColumnSetting>,
50 pub span: Span,
51}
52
53#[derive(Debug, Clone)]
54pub enum ColumnSetting {
55 PrimaryKey,
56 NotNull,
57 Null,
58 Unique,
59 Increment,
60 Default(DefaultValue),
61 Note(StringLiteral),
62 Ref(InlineRef),
63}
64
65#[derive(Debug, Clone)]
66pub enum DefaultValue {
67 String(String),
68 Number(String),
69 Boolean(bool),
70 Expression(String),
71}
72
73#[derive(Debug, Clone)]
74pub struct InlineRef {
75 pub target_table: Ident,
76 pub target_column: Ident,
77 pub relationship: RelationshipType,
78 pub span: Span,
79}
80
81#[derive(Debug, Clone)]
82pub enum RelationshipType {
83 OneToOne, OneToMany, ManyToOne, ManyToMany, }
88
89#[derive(Debug, Clone)]
90pub struct Ref {
91 pub name: Option<Ident>,
92 pub from_table: Ident,
93 pub from_columns: Vec<Ident>,
94 pub to_table: Ident,
95 pub to_columns: Vec<Ident>,
96 pub relationship: RelationshipType,
97 pub span: Span,
98}
99
100#[derive(Debug, Clone)]
101pub struct IndexesBlock {
102 pub indexes: Vec<Index>,
103 pub span: Span,
104}
105
106#[derive(Debug, Clone)]
107pub struct Index {
108 pub columns: Vec<IndexColumn>,
109 pub settings: Vec<IndexSetting>,
110 pub span: Span,
111}
112
113#[derive(Debug, Clone)]
114pub enum IndexColumn {
115 Simple(Ident),
116 Expression(String),
117}
118
119#[derive(Debug, Clone)]
120pub enum IndexSetting {
121 PrimaryKey,
122 Unique,
123 Name(String),
124 Type(String),
125}
126
127#[derive(Debug, Clone)]
128pub struct Enum {
129 pub name: Ident,
130 pub members: Vec<EnumMember>,
131 pub span: Span,
132}
133
134#[derive(Debug, Clone)]
135pub struct EnumMember {
136 pub name: Ident,
137 pub note: Option<StringLiteral>,
138 pub span: Span,
139}
140
141#[derive(Debug, Clone)]
142pub struct Project {
143 pub name: Option<Ident>,
144 pub settings: Vec<ProjectSetting>,
145 pub span: Span,
146}
147
148#[derive(Debug, Clone)]
149pub enum ProjectSetting {
150 DatabaseType(String),
151 Note(StringLiteral),
152}
153
154#[derive(Debug, Clone)]
155pub struct TableSetting {
156 pub key: String,
157 pub value: String,
158}
159
160#[derive(Debug, Clone)]
161pub struct StringLiteral {
162 pub value: String,
163 pub span: Span,
164}