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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! Attribute markers for SQLiteTable derive macro.
//!
//! These const markers are used within `#[column(...)]` and `#[SQLiteTable(...)]`
//! attributes. Import them from the prelude to get IDE hover documentation.
//!
//! # Example
//! ```ignore
//! # use drizzle::sqlite::prelude::*;
//!
//! #[SQLiteTable(name = "users", strict)]
//! struct User {
//! #[column(primary, autoincrement)]
//! id: i32,
//! #[column(unique)]
//! email: String,
//! metadata: String,
//! }
//! ```
/// Marker struct for column constraint attributes.
;
//------------------------------------------------------------------------------
// Primary Key Constraints
//------------------------------------------------------------------------------
/// Marks this column as the PRIMARY KEY.
///
/// ## Example
/// ```ignore
/// #[column(primary)]
/// id: i32,
/// ```
///
/// See: <https://sqlite.org/lang_createtable.html#primkeyconst>
pub const PRIMARY: ColumnMarker = ColumnMarker;
/// Alias for [`PRIMARY`].
pub const PRIMARY_KEY: ColumnMarker = ColumnMarker;
/// Enables AUTOINCREMENT for INTEGER PRIMARY KEY columns.
///
/// ## Example
/// ```ignore
/// #[column(primary, autoincrement)]
/// id: i32,
/// ```
///
/// See: <https://sqlite.org/autoinc.html>
pub const AUTOINCREMENT: ColumnMarker = ColumnMarker;
//------------------------------------------------------------------------------
// Uniqueness Constraints
//------------------------------------------------------------------------------
/// Adds a UNIQUE constraint to this column.
///
/// ## Example
/// ```ignore
/// #[column(unique)]
/// email: String,
/// ```
///
/// See: <https://sqlite.org/lang_createtable.html#unique_constraints>
pub const UNIQUE: ColumnMarker = ColumnMarker;
//------------------------------------------------------------------------------
// Serialization Modes
//------------------------------------------------------------------------------
/// Enables JSON serialization with TEXT storage.
///
/// ## Example
/// ```ignore
/// #[column(json)]
/// metadata: UserMetadata,
/// ```
///
/// Requires the `serde` feature. The field type must implement `Serialize` and `Deserialize`.
pub const JSON: ColumnMarker = ColumnMarker;
/// Enables JSON serialization with BLOB storage.
///
/// ## Example
/// ```ignore
/// #[column(jsonb)]
/// config: AppConfig,
/// ```
///
/// Requires the `serde` feature. The field type must implement `Serialize` and `Deserialize`.
pub const JSONB: ColumnMarker = ColumnMarker;
/// Marks this column as storing an enum type.
///
/// ## Example
/// ```ignore
/// #[column(enum)]
/// role: Role,
///
/// #[column(integer, enum)]
/// status: Status,
/// ```
///
/// The enum must derive `SQLiteEnum`.
pub const ENUM: ColumnMarker = ColumnMarker;
//------------------------------------------------------------------------------
// Default Value Parameters
//------------------------------------------------------------------------------
/// Specifies a function to generate default values at runtime.
///
/// The function is called for each insert when no value is provided.
///
/// ## Example
/// ```ignore
/// #[column(default_fn = Uuid::new_v4)]
/// id: Uuid,
/// ```
///
/// ## Difference from DEFAULT
/// - `default_fn`: Calls the function at runtime for each insert (e.g., UUID generation)
/// - `default`: Uses a fixed compile-time value
pub const DEFAULT_FN: ColumnMarker = ColumnMarker;
/// Specifies a fixed default value for new rows.
///
/// ## Example
/// ```ignore
/// #[column(default = 0)]
/// count: i32,
///
/// #[column(default = "guest")]
/// role: String,
/// ```
///
/// For runtime-generated values (UUIDs, timestamps), use [`DEFAULT_FN`] instead.
pub const DEFAULT: ColumnMarker = ColumnMarker;
/// Establishes a foreign key reference to another table's column.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id)]
/// user_id: i32,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html>
pub const REFERENCES: ColumnMarker = ColumnMarker;
/// Specifies the ON DELETE action for foreign key references.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = CASCADE)]
/// user_id: i32,
/// ```
///
/// ## Supported Actions
/// - `CASCADE`: Delete rows that reference the deleted row
/// - `SET_NULL`: Set the column to NULL when referenced row is deleted
/// - `SET_DEFAULT`: Set the column to its default value
/// - `RESTRICT`: Prevent deletion if referenced
/// - `NO_ACTION`: Similar to RESTRICT (default)
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const ON_DELETE: ColumnMarker = ColumnMarker;
/// Specifies the ON UPDATE action for foreign key references.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_update = CASCADE)]
/// user_id: i32,
/// ```
///
/// ## Supported Actions
/// - `CASCADE`: Update referencing rows when referenced row is updated
/// - `SET_NULL`: Set the column to NULL when referenced row is updated
/// - `SET_DEFAULT`: Set the column to its default value
/// - `RESTRICT`: Prevent update if referenced
/// - `NO_ACTION`: Similar to RESTRICT (default)
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const ON_UPDATE: ColumnMarker = ColumnMarker;
//------------------------------------------------------------------------------
// Referential Action Values
//------------------------------------------------------------------------------
/// Type alias for referential action markers (uses ColumnMarker for macro compatibility).
pub type ReferentialAction = ColumnMarker;
/// CASCADE action: Propagate the delete/update to referencing rows.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = CASCADE)]
/// user_id: i32,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const CASCADE: ColumnMarker = ColumnMarker;
/// SET NULL action: Set referencing columns to NULL.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = SET_NULL)]
/// user_id: Option<i32>,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const SET_NULL: ColumnMarker = ColumnMarker;
/// SET DEFAULT action: Set referencing columns to their default values.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = SET_DEFAULT, default = 0)]
/// user_id: i32,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const SET_DEFAULT: ColumnMarker = ColumnMarker;
/// RESTRICT action: Prevent delete/update if referenced.
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = RESTRICT)]
/// user_id: i32,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const RESTRICT: ColumnMarker = ColumnMarker;
/// NO ACTION action: Similar to RESTRICT (default behavior).
///
/// ## Example
/// ```ignore
/// #[column(references = User::id, on_delete = NO_ACTION)]
/// user_id: i32,
/// ```
///
/// See: <https://sqlite.org/foreignkeys.html#fk_actions>
pub const NO_ACTION: ColumnMarker = ColumnMarker;
//------------------------------------------------------------------------------
// Name Marker (shared by column and table attributes)
//------------------------------------------------------------------------------
/// Marker struct for the NAME attribute.
;
/// Specifies a custom name in the database.
///
/// By default, table, view, and column names are automatically converted to snake_case
/// from the Rust struct/field name. Use NAME to override this behavior.
///
/// ## Column Example
/// ```ignore
/// // Field `createdAt` becomes `created_at` by default
/// created_at: DateTime<Utc>,
///
/// // Override with custom name:
/// #[column(name = "creation_timestamp")]
/// created_at: DateTime<Utc>,
/// ```
///
/// ## Table Example
/// ```ignore
/// // Struct `UserAccount` becomes table `user_account` by default
/// struct UserAccount { ... }
///
/// // Override with custom name:
/// #[SQLiteTable(name = "user_accounts")]
/// struct UserAccount { ... }
/// ```
///
/// ## View Example
/// ```ignore
/// #[SQLiteView(NAME = "active_users")]
/// struct ActiveUsers { ... }
/// ```
pub const NAME: NameMarker = NameMarker;
//------------------------------------------------------------------------------
// View Attribute Markers
//------------------------------------------------------------------------------
/// Marker struct for view attributes.
;
/// Specifies a view definition SQL string or expression.
///
/// ## Examples
/// ```ignore
/// #[SQLiteView(DEFINITION = "SELECT id, email FROM users")]
/// struct UserEmails { id: i32, email: String }
/// ```
///
/// ```ignore
/// #[SQLiteView(
/// DEFINITION = {
/// let builder = drizzle::sqlite::QueryBuilder::new::<Schema>();
/// let Schema { user } = Schema::new();
/// builder.select((user.id, user.email)).from(user)
/// }
/// )]
/// struct UserEmails { id: i32, email: String }
/// ```
pub const DEFINITION: ViewMarker = ViewMarker;
/// Marks the view as existing (skip creation).
///
/// ## Example
/// ```ignore
/// #[SQLiteView(EXISTING)]
/// struct ExistingView { ... }
/// ```
pub const EXISTING: ViewMarker = ViewMarker;
//------------------------------------------------------------------------------
// Table Attribute Markers
//------------------------------------------------------------------------------
/// Marker struct for table-level attributes.
;
/// Enables STRICT mode for the table.
///
/// ## Example
/// ```ignore
/// #[SQLiteTable(strict)]
/// struct Users {
/// #[column(primary)]
/// id: i32,
/// name: String,
/// }
/// ```
///
/// # SQLite Behavior
/// - Enforces that values match declared column types exactly
/// - `INTEGER` columns only accept integers
/// - `TEXT` columns only accept text
/// - `REAL` columns only accept floating-point numbers
/// - `BLOB` columns only accept blobs
/// - `ANY` type allows any value (only in STRICT tables)
///
/// See: <https://sqlite.org/stricttables.html>
pub const STRICT: TableMarker = TableMarker;
/// Enables WITHOUT ROWID optimization for the table.
///
/// ## Example
/// ```ignore
/// #[SQLiteTable(without_rowid)]
/// struct KeyValue {
/// #[column(primary)]
/// key: String,
/// value: String,
/// }
/// ```
///
/// Requires an explicit PRIMARY KEY.
///
/// See: <https://sqlite.org/withoutrowid.html>
pub const WITHOUT_ROWID: TableMarker = TableMarker;
//------------------------------------------------------------------------------
// Column Type Markers
//------------------------------------------------------------------------------
/// Marker struct for column type attributes.
;
/// Specifies an INTEGER column type.
///
/// ## Example
/// ```ignore
/// #[column(integer, primary)]
/// id: i32,
/// ```
///
/// INTEGER columns store signed integers up to 8 bytes (64-bit).
/// SQLite uses a variable-length encoding, so small values use less space.
///
/// See: <https://sqlite.org/datatype3.html#storage_classes_and_datatypes>
pub const INTEGER: TypeMarker = TypeMarker;
/// Specifies a TEXT column type.
///
/// ## Example
/// ```ignore
/// #[column(text)]
/// name: String,
/// ```
///
/// TEXT columns store variable-length UTF-8 character strings with no size limit.
///
/// See: <https://sqlite.org/datatype3.html#storage_classes_and_datatypes>
pub const TEXT: TypeMarker = TypeMarker;
/// Specifies a BLOB column type.
///
/// ## Example
/// ```ignore
/// #[column(blob)]
/// data: Vec<u8>,
/// ```
///
/// BLOB columns store binary data exactly as input.
///
/// See: <https://sqlite.org/datatype3.html#storage_classes_and_datatypes>
pub const BLOB: TypeMarker = TypeMarker;
/// Specifies a REAL column type.
///
/// ## Example
/// ```ignore
/// #[column(real)]
/// price: f64,
/// ```
///
/// REAL columns store 8-byte IEEE floating point numbers.
///
/// See: <https://sqlite.org/datatype3.html#storage_classes_and_datatypes>
pub const REAL: TypeMarker = TypeMarker;
/// Specifies a NUMERIC column type.
///
/// ## Example
/// ```ignore
/// #[column(numeric)]
/// amount: f64,
/// ```
///
/// NUMERIC columns store values as INTEGER, REAL, or TEXT depending on the value.
///
/// See: <https://sqlite.org/datatype3.html#type_affinity>
pub const NUMERIC: TypeMarker = TypeMarker;
/// Specifies an ANY column type (STRICT tables only).
///
/// ## Example
/// ```ignore
/// #[SQLiteTable(strict)]
/// struct Data {
/// #[column(any)]
/// value: serde_json::Value,
/// }
/// ```
///
/// ANY allows any type of data. Only valid in STRICT tables.
///
/// See: <https://sqlite.org/stricttables.html>
pub const ANY: TypeMarker = TypeMarker;
/// Specifies a BOOLEAN column (stored as INTEGER 0/1).
///
/// ## Example
/// ```ignore
/// #[column(boolean)]
/// active: bool,
/// ```
///
/// SQLite has no native BOOLEAN. Values are stored as INTEGER (0 for false, 1 for true).
///
/// See: <https://sqlite.org/datatype3.html#boolean_datatype>
pub const BOOLEAN: TypeMarker = TypeMarker;