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
//! Type-safe date/time functions.
//!
//! These functions work with `Temporal` types (Date, Time, Timestamp, TimestampTz)
//! and provide compile-time enforcement of temporal operations.
//!
//! # Database Compatibility
//!
//! Some functions are database-specific:
//! - SQLite: `date()`, `time()`, `datetime()`, `strftime()`, `julianday()`
//! - PostgreSQL: `now()`, `date_trunc()`, `extract()`, `age()`
//!
//! Cross-database functions try to use compatible SQL where possible.
use crate;
use crateSQLParam;
use crate;
use ;
// =============================================================================
// CURRENT DATE/TIME (Cross-database)
// =============================================================================
/// CURRENT_DATE - returns the current date.
///
/// Works on both SQLite and PostgreSQL.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::current_date;
///
/// // SELECT CURRENT_DATE
/// let today = current_date::<SQLiteValue>();
/// ```
/// CURRENT_TIME - returns the current time.
///
/// Works on both SQLite and PostgreSQL.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::current_time;
///
/// // SELECT CURRENT_TIME
/// let now_time = current_time::<SQLiteValue>();
/// ```
/// CURRENT_TIMESTAMP - returns the current timestamp.
///
/// Works on both SQLite and PostgreSQL.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::current_timestamp;
///
/// // SELECT CURRENT_TIMESTAMP
/// let now = current_timestamp::<SQLiteValue>();
/// ```
// =============================================================================
// SQLite-specific DATE/TIME FUNCTIONS
// =============================================================================
/// DATE - extracts the date part from a temporal expression (SQLite).
///
/// Preserves the nullability of the input expression.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::date;
///
/// // SELECT DATE(users.created_at)
/// let created_date = date(users.created_at);
/// ```
/// TIME - extracts the time part from a temporal expression (SQLite).
///
/// Preserves the nullability of the input expression.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::time;
///
/// // SELECT TIME(users.created_at)
/// let created_time = time(users.created_at);
/// ```
/// DATETIME - creates a datetime from a temporal expression (SQLite).
///
/// Preserves the nullability of the input expression.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::datetime;
///
/// // SELECT DATETIME(users.created_at)
/// let dt = datetime(users.created_at);
/// ```
/// STRFTIME - formats a temporal expression as text (SQLite).
///
/// Returns Text type, preserves nullability of the time value.
///
/// # Format Specifiers (common)
///
/// - `%Y` - 4-digit year
/// - `%m` - month (01-12)
/// - `%d` - day of month (01-31)
/// - `%H` - hour (00-23)
/// - `%M` - minute (00-59)
/// - `%S` - second (00-59)
/// - `%s` - Unix timestamp
/// - `%w` - day of week (0-6, Sunday=0)
/// - `%j` - day of year (001-366)
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::strftime;
///
/// // SELECT STRFTIME('%Y-%m-%d', users.created_at)
/// let formatted = strftime("%Y-%m-%d", users.created_at);
/// ```
/// JULIANDAY - converts a temporal expression to Julian day number (SQLite).
///
/// Returns Double type, preserves nullability.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::julianday;
///
/// // SELECT JULIANDAY(users.created_at)
/// let julian = julianday(users.created_at);
/// ```
/// UNIXEPOCH - converts a temporal expression to Unix timestamp (SQLite 3.38+).
///
/// Returns BigInt type (seconds since 1970-01-01), preserves nullability.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::unixepoch;
///
/// // SELECT UNIXEPOCH(users.created_at)
/// let unix_ts = unixepoch(users.created_at);
/// ```
// =============================================================================
// PostgreSQL-specific DATE/TIME FUNCTIONS
// =============================================================================
/// NOW - returns the current timestamp with time zone (PostgreSQL).
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::now;
///
/// // SELECT NOW()
/// let current = now::<PostgresValue>();
/// ```
/// DATE_TRUNC - truncates a timestamp to specified precision (PostgreSQL).
///
/// Truncates the timestamp to the specified precision. Common values:
/// 'microseconds', 'milliseconds', 'second', 'minute', 'hour',
/// 'day', 'week', 'month', 'quarter', 'year', 'decade', 'century', 'millennium'
///
/// Preserves the nullability of the input expression.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::date_trunc;
///
/// // SELECT DATE_TRUNC('month', users.created_at)
/// let month_start = date_trunc("month", users.created_at);
/// ```
/// EXTRACT - extracts a component from a temporal expression (PostgreSQL/Standard SQL).
///
/// Returns Double type. Common fields:
/// 'year', 'month', 'day', 'hour', 'minute', 'second',
/// 'dow' (day of week), 'doy' (day of year), 'epoch' (Unix timestamp)
///
/// Preserves the nullability of the input expression.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::extract;
///
/// // SELECT EXTRACT(YEAR FROM users.created_at)
/// let year = extract("YEAR", users.created_at);
/// ```
/// AGE - calculates the interval between two timestamps (PostgreSQL).
///
/// Returns Text (interval representation). The result is nullable if either input is nullable.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::age;
///
/// // SELECT AGE(NOW(), users.created_at)
/// let user_age = age(now(), users.created_at);
/// ```
/// TO_CHAR - formats a temporal expression as text (PostgreSQL).
///
/// Returns Text type, preserves nullability of the input expression.
///
/// # Common Format Patterns
///
/// - `YYYY` - 4-digit year
/// - `MM` - month (01-12)
/// - `DD` - day of month (01-31)
/// - `HH24` - hour (00-23)
/// - `MI` - minute (00-59)
/// - `SS` - second (00-59)
/// - `Day` - full day name
/// - `Month` - full month name
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::to_char;
///
/// // SELECT TO_CHAR(users.created_at, 'YYYY-MM-DD')
/// let formatted = to_char(users.created_at, "YYYY-MM-DD");
/// ```
/// TO_TIMESTAMP - converts a Unix timestamp to a timestamp (PostgreSQL).
///
/// Returns Timestamp type. The input should be a numeric Unix timestamp.
///
/// # Example
///
/// ```ignore
/// use drizzle_core::expr::to_timestamp;
///
/// // SELECT TO_TIMESTAMP(users.created_unix)
/// let ts = to_timestamp(users.created_unix);
/// ```