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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//! # prax-schema
//!
//! Schema parser and AST for the Prax ORM.
//!
//! This crate provides:
//! - Schema Definition Language (SDL) parser for `.prax` files
//! - Configuration parser for `prax.toml` files
//! - Abstract Syntax Tree (AST) types for schema representation
//! - Schema validation and semantic analysis
//!
//! ## Quick Start
//!
//! Parse a schema string:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! model User {
//! id Int @id @auto
//! email String @unique
//! name String?
//! }
//! "#).unwrap();
//!
//! assert!(schema.get_model("User").is_some());
//! ```
//!
//! ## Parsing Models
//!
//! Models define database tables with typed fields:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! model Post {
//! id Int @id @auto
//! title String
//! content String?
//! published Boolean @default(false)
//! viewCount Int @default(0)
//! }
//! "#).unwrap();
//!
//! let post = schema.get_model("Post").unwrap();
//! assert_eq!(post.fields.len(), 5);
//!
//! // Check field properties
//! let title = post.fields.get("title").unwrap();
//! assert!(!title.is_optional());
//!
//! let content = post.fields.get("content").unwrap();
//! assert!(content.is_optional());
//! ```
//!
//! ## Parsing Enums
//!
//! Enums define custom value types:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! enum Role {
//! User
//! Admin
//! Moderator
//! }
//!
//! model User {
//! id Int @id @auto
//! role Role @default(User)
//! }
//! "#).unwrap();
//!
//! let role_enum = schema.get_enum("Role").unwrap();
//! assert_eq!(role_enum.variants.len(), 3);
//! ```
//!
//! ## Parsing Relations
//!
//! Relations define relationships between models:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! model User {
//! id Int @id @auto
//! posts Post[]
//! }
//!
//! model Post {
//! id Int @id @auto
//! authorId Int
//! author User @relation(fields: [authorId], references: [id])
//! }
//! "#).unwrap();
//!
//! let post = schema.get_model("Post").unwrap();
//! let author_field = post.fields.get("author").unwrap();
//! assert!(author_field.is_relation());
//! ```
//!
//! ## Parsing Views
//!
//! Views represent SQL views:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! model User {
//! id Int @id @auto
//! active Boolean
//! }
//!
//! view ActiveUsers {
//! id Int @unique
//!
//! @@map("active_users_view")
//! }
//! "#).unwrap();
//!
//! assert!(schema.get_view("ActiveUsers").is_some());
//! ```
//!
//! ## Parsing Server Groups
//!
//! Server groups define multi-server configurations:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! serverGroup MainCluster {
//! server primary {
//! url = "postgres://primary/db"
//! role = "primary"
//! }
//!
//! server replica1 {
//! url = "postgres://replica1/db"
//! role = "replica"
//! weight = 100
//! }
//!
//! @@strategy("ReadReplica")
//! @@loadBalance("RoundRobin")
//! }
//! "#).unwrap();
//!
//! let cluster = schema.get_server_group("MainCluster").unwrap();
//! assert_eq!(cluster.servers.len(), 2);
//! ```
//!
//! ## Schema Validation
//!
//! Validate schemas for correctness:
//!
//! ```rust
//! use prax_schema::validate_schema;
//!
//! // Valid schema passes validation
//! let result = validate_schema(r#"
//! model User {
//! id Int @id @auto
//! email String @unique
//! }
//! "#);
//! assert!(result.is_ok());
//!
//! // Schema with relations validates correctly
//! let result = validate_schema(r#"
//! model User {
//! id Int @id @auto
//! posts Post[]
//! }
//! model Post {
//! id Int @id @auto
//! authorId Int
//! author User @relation(fields: [authorId], references: [id])
//! }
//! "#);
//! assert!(result.is_ok());
//! ```
//!
//! ## Schema Statistics
//!
//! Get statistics about a schema:
//!
//! ```rust
//! use prax_schema::parse_schema;
//!
//! let schema = parse_schema(r#"
//! model User { id Int @id @auto }
//! model Post { id Int @id @auto }
//! enum Role { User Admin }
//! type Address { street String }
//! "#).unwrap();
//!
//! let stats = schema.stats();
//! assert_eq!(stats.model_count, 2);
//! assert_eq!(stats.enum_count, 1);
//! assert_eq!(stats.type_count, 1);
//! ```
//!
//! ## Configuration Parsing
//!
//! Parse `prax.toml` configuration:
//!
//! ```rust
//! use prax_schema::config::PraxConfig;
//!
//! let config: PraxConfig = toml::from_str(r#"
//! [database]
//! provider = "postgresql"
//! url = "postgres://localhost/mydb"
//!
//! [database.pool]
//! max_connections = 10
//!
//! [generator.client]
//! output = "./src/generated"
//! "#).unwrap();
//!
//! assert_eq!(config.database.pool.max_connections, 10);
//! ```
//!
//! ## Prelude
//!
//! Import commonly used types:
//!
//! ```rust
//! use prax_schema::prelude::*;
//!
//! // Now you can use parse_schema, Schema, etc.
//! let schema = parse_schema("model User { id Int @id }").unwrap();
//! ```
pub use *;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Prelude module for convenient imports.