drizzle_sqlite/pragma.rs
1//! SQLite PRAGMA statements for database configuration and introspection
2//!
3//! This module provides type-safe, ergonomic access to SQLite's PRAGMA statements.
4//! PRAGMA statements are SQL extension specific to SQLite and are used to modify
5//! the operation of the SQLite library or to query the SQLite library for internal
6//! (non-table) data.
7//!
8//! [SQLite PRAGMA Documentation](https://sqlite.org/pragma.html)
9//!
10//! ## Features
11//!
12//! - **Type Safety**: Enums for all pragma values (no string literals needed)
13//! - **Ergonomic API**: Uses `&'static str` instead of `String` - no `.to_string()` calls
14//! - **Documentation Links**: Each pragma links to official SQLite documentation
15//! - **ToSQL Integration**: Seamless integration with the query builder
16//!
17//! ## Categories
18//!
19//! - **Configuration**: `foreign_keys`, `journal_mode`, `wal_autocheckpoint`, `cache_spill`, etc.
20//! - **Introspection**: `table_info`, `index_list`, `compile_options`, etc.
21//! - **Maintenance**: `integrity_check`, `incremental_vacuum`, `wal_checkpoint`, etc.
22//!
23//! ## Examples
24//!
25//! ```
26//! use drizzle_sqlite::pragma::{Pragma, JournalMode, AutoVacuum};
27//! use drizzle_core::ToSQL;
28//!
29//! // Enable foreign key constraints
30//! let pragma = Pragma::foreign_keys(true);
31//! assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_keys = ON");
32//!
33//! // Set journal mode to WAL
34//! let pragma = Pragma::journal_mode(JournalMode::Wal);
35//! assert_eq!(pragma.to_sql().sql(), "PRAGMA journal_mode = WAL");
36//!
37//! // Get table schema information
38//! let pragma = Pragma::table_info("users");
39//! assert_eq!(pragma.to_sql().sql(), "PRAGMA table_info(users)");
40//!
41//! // Check database integrity
42//! let pragma = Pragma::integrity_check(None);
43//! assert_eq!(pragma.to_sql().sql(), "PRAGMA integrity_check");
44//! ```
45
46use crate::values::SQLiteValue;
47use drizzle_core::{SQL, ToSQL};
48
49/// Auto-vacuum modes for SQLite databases
50///
51/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_auto_vacuum)
52#[derive(Debug, Clone, PartialEq)]
53pub enum AutoVacuum {
54 /// Disable auto-vacuum
55 ///
56 /// # Example
57 /// ```
58 /// # use drizzle_sqlite::pragma::AutoVacuum;
59 /// # use drizzle_core::ToSQL;
60 /// assert_eq!(AutoVacuum::None.to_sql().sql(), "NONE");
61 /// ```
62 None,
63
64 /// Enable full auto-vacuum
65 ///
66 /// # Example
67 /// ```
68 /// # use drizzle_sqlite::pragma::AutoVacuum;
69 /// # use drizzle_core::ToSQL;
70 /// assert_eq!(AutoVacuum::Full.to_sql().sql(), "FULL");
71 /// ```
72 Full,
73
74 /// Enable incremental auto-vacuum
75 ///
76 /// # Example
77 /// ```
78 /// # use drizzle_sqlite::pragma::AutoVacuum;
79 /// # use drizzle_core::ToSQL;
80 /// assert_eq!(AutoVacuum::Incremental.to_sql().sql(), "INCREMENTAL");
81 /// ```
82 Incremental,
83}
84
85/// Journal modes for SQLite databases
86///
87/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_journal_mode)
88#[derive(Debug, Clone, PartialEq)]
89pub enum JournalMode {
90 /// Delete journal file after each transaction
91 ///
92 /// # Example
93 /// ```
94 /// # use drizzle_sqlite::pragma::JournalMode;
95 /// # use drizzle_core::ToSQL;
96 /// assert_eq!(JournalMode::Delete.to_sql().sql(), "DELETE");
97 /// ```
98 Delete,
99
100 /// Truncate journal file after each transaction
101 ///
102 /// # Example
103 /// ```
104 /// # use drizzle_sqlite::pragma::JournalMode;
105 /// # use drizzle_core::ToSQL;
106 /// assert_eq!(JournalMode::Truncate.to_sql().sql(), "TRUNCATE");
107 /// ```
108 Truncate,
109
110 /// Keep journal file persistent
111 ///
112 /// # Example
113 /// ```
114 /// # use drizzle_sqlite::pragma::JournalMode;
115 /// # use drizzle_core::ToSQL;
116 /// assert_eq!(JournalMode::Persist.to_sql().sql(), "PERSIST");
117 /// ```
118 Persist,
119
120 /// Store journal in memory
121 ///
122 /// # Example
123 /// ```
124 /// # use drizzle_sqlite::pragma::JournalMode;
125 /// # use drizzle_core::ToSQL;
126 /// assert_eq!(JournalMode::Memory.to_sql().sql(), "MEMORY");
127 /// ```
128 Memory,
129
130 /// Write-Ahead Logging mode
131 ///
132 /// # Example
133 /// ```
134 /// # use drizzle_sqlite::pragma::JournalMode;
135 /// # use drizzle_core::ToSQL;
136 /// assert_eq!(JournalMode::Wal.to_sql().sql(), "WAL");
137 /// ```
138 Wal,
139
140 /// Disable journaling
141 ///
142 /// # Example
143 /// ```
144 /// # use drizzle_sqlite::pragma::JournalMode;
145 /// # use drizzle_core::ToSQL;
146 /// assert_eq!(JournalMode::Off.to_sql().sql(), "OFF");
147 /// ```
148 Off,
149}
150
151/// Synchronous modes for SQLite databases
152///
153/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_synchronous)
154#[derive(Debug, Clone, PartialEq)]
155pub enum Synchronous {
156 /// No syncing - fastest but least safe
157 ///
158 /// # Example
159 /// ```
160 /// # use drizzle_sqlite::pragma::Synchronous;
161 /// # use drizzle_core::ToSQL;
162 /// assert_eq!(Synchronous::Off.to_sql().sql(), "OFF");
163 /// ```
164 Off,
165
166 /// Sync at critical moments - good balance
167 ///
168 /// # Example
169 /// ```
170 /// # use drizzle_sqlite::pragma::Synchronous;
171 /// # use drizzle_core::ToSQL;
172 /// assert_eq!(Synchronous::Normal.to_sql().sql(), "NORMAL");
173 /// ```
174 Normal,
175
176 /// Sync frequently - safest but slower
177 ///
178 /// # Example
179 /// ```
180 /// # use drizzle_sqlite::pragma::Synchronous;
181 /// # use drizzle_core::ToSQL;
182 /// assert_eq!(Synchronous::Full.to_sql().sql(), "FULL");
183 /// ```
184 Full,
185
186 /// Like FULL with additional syncing
187 ///
188 /// # Example
189 /// ```
190 /// # use drizzle_sqlite::pragma::Synchronous;
191 /// # use drizzle_core::ToSQL;
192 /// assert_eq!(Synchronous::Extra.to_sql().sql(), "EXTRA");
193 /// ```
194 Extra,
195}
196
197/// Storage modes for temporary tables and indices
198///
199/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_temp_store)
200#[derive(Debug, Clone, PartialEq)]
201pub enum TempStore {
202 /// Use default storage mode
203 ///
204 /// # Example
205 /// ```
206 /// # use drizzle_sqlite::pragma::TempStore;
207 /// # use drizzle_core::ToSQL;
208 /// assert_eq!(TempStore::Default.to_sql().sql(), "DEFAULT");
209 /// ```
210 Default,
211
212 /// Store temporary tables in files
213 ///
214 /// # Example
215 /// ```
216 /// # use drizzle_sqlite::pragma::TempStore;
217 /// # use drizzle_core::ToSQL;
218 /// assert_eq!(TempStore::File.to_sql().sql(), "FILE");
219 /// ```
220 File,
221
222 /// Store temporary tables in memory
223 ///
224 /// # Example
225 /// ```
226 /// # use drizzle_sqlite::pragma::TempStore;
227 /// # use drizzle_core::ToSQL;
228 /// assert_eq!(TempStore::Memory.to_sql().sql(), "MEMORY");
229 /// ```
230 Memory,
231}
232
233/// Database locking modes
234///
235/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_locking_mode)
236#[derive(Debug, Clone, PartialEq)]
237pub enum LockingMode {
238 /// Normal locking mode - allows multiple readers
239 ///
240 /// # Example
241 /// ```
242 /// # use drizzle_sqlite::pragma::LockingMode;
243 /// # use drizzle_core::ToSQL;
244 /// assert_eq!(LockingMode::Normal.to_sql().sql(), "NORMAL");
245 /// ```
246 Normal,
247
248 /// Exclusive locking mode - single connection only
249 ///
250 /// # Example
251 /// ```
252 /// # use drizzle_sqlite::pragma::LockingMode;
253 /// # use drizzle_core::ToSQL;
254 /// assert_eq!(LockingMode::Exclusive.to_sql().sql(), "EXCLUSIVE");
255 /// ```
256 Exclusive,
257}
258
259/// Secure delete modes for SQLite
260///
261/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_secure_delete)
262#[derive(Debug, Clone, PartialEq)]
263pub enum SecureDelete {
264 /// Disable secure delete
265 ///
266 /// # Example
267 /// ```
268 /// # use drizzle_sqlite::pragma::SecureDelete;
269 /// # use drizzle_core::ToSQL;
270 /// assert_eq!(SecureDelete::Off.to_sql().sql(), "OFF");
271 /// ```
272 Off,
273
274 /// Enable secure delete - overwrite deleted data
275 ///
276 /// # Example
277 /// ```
278 /// # use drizzle_sqlite::pragma::SecureDelete;
279 /// # use drizzle_core::ToSQL;
280 /// assert_eq!(SecureDelete::On.to_sql().sql(), "ON");
281 /// ```
282 On,
283
284 /// Fast secure delete - partial overwriting
285 ///
286 /// # Example
287 /// ```
288 /// # use drizzle_sqlite::pragma::SecureDelete;
289 /// # use drizzle_core::ToSQL;
290 /// assert_eq!(SecureDelete::Fast.to_sql().sql(), "FAST");
291 /// ```
292 Fast,
293}
294
295/// Encoding types for SQLite databases
296///
297/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_encoding)
298#[derive(Debug, Clone, PartialEq)]
299pub enum Encoding {
300 /// UTF-8 encoding
301 ///
302 /// # Example
303 /// ```
304 /// # use drizzle_sqlite::pragma::Encoding;
305 /// # use drizzle_core::ToSQL;
306 /// assert_eq!(Encoding::Utf8.to_sql().sql(), "UTF-8");
307 /// ```
308 Utf8,
309
310 /// UTF-16 little endian encoding
311 ///
312 /// # Example
313 /// ```
314 /// # use drizzle_sqlite::pragma::Encoding;
315 /// # use drizzle_core::ToSQL;
316 /// assert_eq!(Encoding::Utf16Le.to_sql().sql(), "UTF-16LE");
317 /// ```
318 Utf16Le,
319
320 /// UTF-16 big endian encoding
321 ///
322 /// # Example
323 /// ```
324 /// # use drizzle_sqlite::pragma::Encoding;
325 /// # use drizzle_core::ToSQL;
326 /// assert_eq!(Encoding::Utf16Be.to_sql().sql(), "UTF-16BE");
327 /// ```
328 Utf16Be,
329}
330
331/// Cache spill settings for SQLite databases
332///
333/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_cache_spill)
334#[derive(Debug, Clone, PartialEq)]
335pub enum CacheSpill {
336 /// Enable or disable cache spilling
337 ///
338 /// # Example
339 /// ```
340 /// # use drizzle_sqlite::pragma::CacheSpill;
341 /// # use drizzle_core::ToSQL;
342 /// let setting = CacheSpill::Enabled(true);
343 /// assert_eq!(setting.to_sql().sql(), "ON");
344 /// ```
345 Enabled(bool),
346
347 /// Set the spill threshold (pages)
348 ///
349 /// # Example
350 /// ```
351 /// # use drizzle_sqlite::pragma::CacheSpill;
352 /// # use drizzle_core::ToSQL;
353 /// let setting = CacheSpill::Pages(1000);
354 /// assert_eq!(setting.to_sql().sql(), "1000");
355 /// ```
356 Pages(i32),
357}
358
359/// WAL checkpoint modes
360///
361/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_wal_checkpoint)
362#[derive(Debug, Clone, PartialEq)]
363pub enum WalCheckpointMode {
364 /// Passive checkpoint
365 Passive,
366 /// Full checkpoint
367 Full,
368 /// Restart checkpoint
369 Restart,
370 /// Truncate checkpoint
371 Truncate,
372 /// No-op checkpoint (query status only)
373 Noop,
374}
375
376/// Writable schema modes (test-only)
377///
378/// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_writable_schema)
379#[derive(Debug, Clone, PartialEq)]
380pub enum WritableSchema {
381 /// Enable or disable writable schema mode
382 Enabled(bool),
383 /// Reset the writable_schema setting
384 Reset,
385}
386
387/// SQLite pragma statements for database configuration and introspection
388#[derive(Debug, Clone, PartialEq)]
389pub enum Pragma {
390 // Read/Write Configuration Pragmas
391 /// Set or query the 32-bit signed big-endian application ID
392 ///
393 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_application_id)
394 ///
395 /// # Example
396 /// ```
397 /// # use drizzle_sqlite::pragma::Pragma;
398 /// # use drizzle_core::ToSQL;
399 /// let pragma = Pragma::ApplicationId(12345);
400 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA application_id = 12345");
401 /// ```
402 ApplicationId(i32),
403
404 /// Query or set the auto-vacuum status in the database
405 ///
406 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_auto_vacuum)
407 ///
408 /// # Example
409 /// ```
410 /// # use drizzle_sqlite::pragma::{Pragma, AutoVacuum};
411 /// # use drizzle_core::ToSQL;
412 /// let pragma = Pragma::AutoVacuum(AutoVacuum::Full);
413 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA auto_vacuum = FULL");
414 /// ```
415 AutoVacuum(AutoVacuum),
416
417 /// Suggest maximum number of database disk pages in memory
418 ///
419 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_cache_size)
420 ///
421 /// # Example
422 /// ```
423 /// # use drizzle_sqlite::pragma::Pragma;
424 /// # use drizzle_core::ToSQL;
425 /// let pragma = Pragma::CacheSize(-2000);
426 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA cache_size = -2000");
427 /// ```
428 CacheSize(i32),
429
430 /// Query, set, or clear the enforcement of foreign key constraints
431 ///
432 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_foreign_keys)
433 ///
434 /// # Example
435 /// ```
436 /// # use drizzle_sqlite::pragma::Pragma;
437 /// # use drizzle_core::ToSQL;
438 /// let pragma = Pragma::ForeignKeys(true);
439 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_keys = ON");
440 ///
441 /// let pragma = Pragma::ForeignKeys(false);
442 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_keys = OFF");
443 /// ```
444 ForeignKeys(bool),
445
446 /// Query or set the journal mode for databases
447 ///
448 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_journal_mode)
449 ///
450 /// # Example
451 /// ```
452 /// # use drizzle_sqlite::pragma::{Pragma, JournalMode};
453 /// # use drizzle_core::ToSQL;
454 /// let pragma = Pragma::JournalMode(JournalMode::Wal);
455 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA journal_mode = WAL");
456 /// ```
457 JournalMode(JournalMode),
458
459 /// Query or set the WAL auto-checkpoint threshold (pages)
460 ///
461 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_wal_autocheckpoint)
462 ///
463 /// # Example
464 /// ```
465 /// # use drizzle_sqlite::pragma::Pragma;
466 /// # use drizzle_core::ToSQL;
467 /// let pragma = Pragma::WalAutocheckpoint(1000);
468 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA wal_autocheckpoint = 1000");
469 /// ```
470 WalAutocheckpoint(i32),
471
472 /// Control how aggressively SQLite will write data
473 ///
474 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_synchronous)
475 ///
476 /// # Example
477 /// ```
478 /// # use drizzle_sqlite::pragma::{Pragma, Synchronous};
479 /// # use drizzle_core::ToSQL;
480 /// let pragma = Pragma::Synchronous(Synchronous::Normal);
481 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA synchronous = NORMAL");
482 /// ```
483 Synchronous(Synchronous),
484
485 /// Query or set the storage mode used by temporary tables and indices
486 ///
487 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_temp_store)
488 ///
489 /// # Example
490 /// ```
491 /// # use drizzle_sqlite::pragma::{Pragma, TempStore};
492 /// # use drizzle_core::ToSQL;
493 /// let pragma = Pragma::TempStore(TempStore::Memory);
494 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA temp_store = MEMORY");
495 /// ```
496 TempStore(TempStore),
497
498 /// Query or set the database connection locking-mode
499 ///
500 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_locking_mode)
501 ///
502 /// # Example
503 /// ```
504 /// # use drizzle_sqlite::pragma::{Pragma, LockingMode};
505 /// # use drizzle_core::ToSQL;
506 /// let pragma = Pragma::LockingMode(LockingMode::Exclusive);
507 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA locking_mode = EXCLUSIVE");
508 /// ```
509 LockingMode(LockingMode),
510
511 /// Query or set the secure-delete setting
512 ///
513 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_secure_delete)
514 ///
515 /// # Example
516 /// ```
517 /// # use drizzle_sqlite::pragma::{Pragma, SecureDelete};
518 /// # use drizzle_core::ToSQL;
519 /// let pragma = Pragma::SecureDelete(SecureDelete::Fast);
520 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA secure_delete = FAST");
521 /// ```
522 SecureDelete(SecureDelete),
523
524 /// Set or get the user-version integer
525 ///
526 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_user_version)
527 ///
528 /// # Example
529 /// ```
530 /// # use drizzle_sqlite::pragma::Pragma;
531 /// # use drizzle_core::ToSQL;
532 /// let pragma = Pragma::UserVersion(42);
533 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA user_version = 42");
534 /// ```
535 UserVersion(i32),
536
537 /// Query or set the text encoding used by the database
538 ///
539 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_encoding)
540 ///
541 /// # Example
542 /// ```
543 /// # use drizzle_sqlite::pragma::{Pragma, Encoding};
544 /// # use drizzle_core::ToSQL;
545 /// let pragma = Pragma::Encoding(Encoding::Utf8);
546 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA encoding = UTF-8");
547 /// ```
548 Encoding(Encoding),
549
550 /// Query or set the database page size in bytes
551 ///
552 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_page_size)
553 ///
554 /// # Example
555 /// ```
556 /// # use drizzle_sqlite::pragma::Pragma;
557 /// # use drizzle_core::ToSQL;
558 /// let pragma = Pragma::PageSize(4096);
559 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA page_size = 4096");
560 /// ```
561 PageSize(i32),
562
563 /// Query or set the maximum memory map size
564 ///
565 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_mmap_size)
566 ///
567 /// # Example
568 /// ```
569 /// # use drizzle_sqlite::pragma::Pragma;
570 /// # use drizzle_core::ToSQL;
571 /// let pragma = Pragma::MmapSize(268435456);
572 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA mmap_size = 268435456");
573 /// ```
574 MmapSize(i64),
575
576 /// Enable or disable recursive trigger firing
577 ///
578 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_recursive_triggers)
579 ///
580 /// # Example
581 /// ```
582 /// # use drizzle_sqlite::pragma::Pragma;
583 /// # use drizzle_core::ToSQL;
584 /// let pragma = Pragma::RecursiveTriggers(true);
585 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA recursive_triggers = ON");
586 /// ```
587 RecursiveTriggers(bool),
588
589 /// Query or set the ANALYZE limit
590 ///
591 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_analysis_limit)
592 AnalysisLimit(i32),
593
594 /// Query or set automatic indexing
595 ///
596 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_automatic_index)
597 AutomaticIndex(bool),
598
599 /// Query or set the busy timeout (milliseconds)
600 ///
601 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_busy_timeout)
602 BusyTimeout(i32),
603
604 /// Query or set cache spill settings
605 ///
606 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_cache_spill)
607 CacheSpill(CacheSpill),
608
609 /// Query or set case_sensitive_like (deprecated)
610 ///
611 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_case_sensitive_like)
612 CaseSensitiveLike(bool),
613
614 /// Enable or disable cell size checking
615 ///
616 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_cell_size_check)
617 CellSizeCheck(bool),
618
619 /// Enable or disable checkpoint fullfsync
620 ///
621 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_checkpoint_fullfsync)
622 CheckpointFullFsync(bool),
623
624 /// Query or set count_changes (deprecated)
625 ///
626 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_count_changes)
627 CountChanges(bool),
628
629 /// Query or set data_store_directory (deprecated)
630 ///
631 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_data_store_directory)
632 DataStoreDirectory(&'static str),
633
634 /// Query or set default_cache_size (deprecated)
635 ///
636 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_default_cache_size)
637 DefaultCacheSize(i32),
638
639 /// Query or set defer_foreign_keys
640 ///
641 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_defer_foreign_keys)
642 DeferForeignKeys(bool),
643
644 /// Query or set empty_result_callbacks (deprecated)
645 ///
646 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_empty_result_callbacks)
647 EmptyResultCallbacks(bool),
648
649 /// Query or set full_column_names (deprecated)
650 ///
651 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_full_column_names)
652 FullColumnNames(bool),
653
654 /// Query or set fullfsync
655 ///
656 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_fullfsync)
657 FullFsync(bool),
658
659 /// Query or set hard_heap_limit
660 ///
661 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_hard_heap_limit)
662 HardHeapLimit(i64),
663
664 /// Query or set ignore_check_constraints
665 ///
666 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_ignore_check_constraints)
667 IgnoreCheckConstraints(bool),
668
669 /// Query or set journal_size_limit
670 ///
671 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_journal_size_limit)
672 JournalSizeLimit(i64),
673
674 /// Query or set legacy_alter_table
675 ///
676 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_legacy_alter_table)
677 LegacyAlterTable(bool),
678
679 /// Query legacy_file_format (deprecated)
680 ///
681 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_legacy_file_format)
682 LegacyFileFormat,
683
684 /// Query or set max_page_count
685 ///
686 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_max_page_count)
687 MaxPageCount(i32),
688
689 /// Query or set query_only
690 ///
691 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_query_only)
692 QueryOnly(bool),
693
694 /// Query or set read_uncommitted
695 ///
696 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_read_uncommitted)
697 ReadUncommitted(bool),
698
699 /// Query or set reverse_unordered_selects
700 ///
701 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_reverse_unordered_selects)
702 ReverseUnorderedSelects(bool),
703
704 /// Query or set schema_version (test-only)
705 ///
706 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_schema_version)
707 SchemaVersion(i32),
708
709 /// Query or set short_column_names (deprecated)
710 ///
711 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_short_column_names)
712 ShortColumnNames(bool),
713
714 /// Query or set soft_heap_limit
715 ///
716 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_soft_heap_limit)
717 SoftHeapLimit(i64),
718
719 /// Query or set temp_store_directory (deprecated)
720 ///
721 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_temp_store_directory)
722 TempStoreDirectory(&'static str),
723
724 /// Query or set threads
725 ///
726 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_threads)
727 Threads(i32),
728
729 /// Query or set trusted_schema
730 ///
731 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_trusted_schema)
732 TrustedSchema(bool),
733
734 /// Query or set writable_schema (test-only)
735 ///
736 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_writable_schema)
737 WritableSchema(WritableSchema),
738
739 /// Query or set parser_trace (requires SQLITE_DEBUG)
740 ///
741 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_parser_trace)
742 ParserTrace(bool),
743
744 /// Query or set vdbe_addoptrace (requires SQLITE_DEBUG)
745 ///
746 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_vdbe_addoptrace)
747 VdbeAddoptrace(bool),
748
749 /// Query or set vdbe_debug (requires SQLITE_DEBUG)
750 ///
751 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_vdbe_debug)
752 VdbeDebug(bool),
753
754 /// Query or set vdbe_listing (requires SQLITE_DEBUG)
755 ///
756 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_vdbe_listing)
757 VdbeListing(bool),
758
759 /// Query or set vdbe_trace (requires SQLITE_DEBUG)
760 ///
761 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_vdbe_trace)
762 VdbeTrace(bool),
763
764 // Read-Only Query Pragmas
765 /// Return a list of collating sequences
766 ///
767 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_collation_list)
768 ///
769 /// # Example
770 /// ```
771 /// # use drizzle_sqlite::pragma::Pragma;
772 /// # use drizzle_core::ToSQL;
773 /// let pragma = Pragma::CollationList;
774 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA collation_list");
775 /// ```
776 CollationList,
777
778 /// Return compile-time options used when building SQLite
779 ///
780 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_compile_options)
781 ///
782 /// # Example
783 /// ```
784 /// # use drizzle_sqlite::pragma::Pragma;
785 /// # use drizzle_core::ToSQL;
786 /// let pragma = Pragma::CompileOptions;
787 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA compile_options");
788 /// ```
789 CompileOptions,
790
791 /// Return information about attached databases
792 ///
793 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_database_list)
794 ///
795 /// # Example
796 /// ```
797 /// # use drizzle_sqlite::pragma::Pragma;
798 /// # use drizzle_core::ToSQL;
799 /// let pragma = Pragma::DatabaseList;
800 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA database_list");
801 /// ```
802 DatabaseList,
803
804 /// Return a list of SQL functions
805 ///
806 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_function_list)
807 ///
808 /// # Example
809 /// ```
810 /// # use drizzle_sqlite::pragma::Pragma;
811 /// # use drizzle_core::ToSQL;
812 /// let pragma = Pragma::FunctionList;
813 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA function_list");
814 /// ```
815 FunctionList,
816
817 /// Return information about tables and views in the schema
818 ///
819 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_table_list)
820 ///
821 /// # Example
822 /// ```
823 /// # use drizzle_sqlite::pragma::Pragma;
824 /// # use drizzle_core::ToSQL;
825 /// let pragma = Pragma::TableList;
826 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA table_list");
827 /// ```
828 TableList,
829
830 /// Return extended table information including hidden columns
831 ///
832 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_table_xinfo)
833 ///
834 /// # Example
835 /// ```
836 /// # use drizzle_sqlite::pragma::Pragma;
837 /// # use drizzle_core::ToSQL;
838 /// let pragma = Pragma::TableXInfo("users");
839 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA table_xinfo(users)");
840 /// ```
841 TableXInfo(&'static str),
842
843 /// Return a list of available virtual table modules
844 ///
845 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_module_list)
846 ///
847 /// # Example
848 /// ```
849 /// # use drizzle_sqlite::pragma::Pragma;
850 /// # use drizzle_core::ToSQL;
851 /// let pragma = Pragma::ModuleList;
852 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA module_list");
853 /// ```
854 ModuleList,
855
856 /// Return the data_version counter
857 ///
858 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_data_version)
859 DataVersion,
860
861 /// Return the number of free pages in the database file
862 ///
863 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_freelist_count)
864 FreelistCount,
865
866 /// Return the page count for the database
867 ///
868 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_page_count)
869 PageCount,
870
871 /// Return a list of available pragmas
872 ///
873 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_pragma_list)
874 PragmaList,
875
876 /// Return statistics (test-only)
877 ///
878 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_stats)
879 Stats,
880
881 // Utility Pragmas
882 /// Perform incremental vacuuming
883 ///
884 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_incremental_vacuum)
885 IncrementalVacuum(Option<i32>),
886
887 /// Release as much memory as possible
888 ///
889 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_shrink_memory)
890 ShrinkMemory,
891
892 /// Run a WAL checkpoint
893 ///
894 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_wal_checkpoint)
895 WalCheckpoint(Option<WalCheckpointMode>),
896
897 /// Perform database integrity check
898 ///
899 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_integrity_check)
900 ///
901 /// # Example
902 /// ```
903 /// # use drizzle_sqlite::pragma::Pragma;
904 /// # use drizzle_core::ToSQL;
905 /// // Check entire database
906 /// let pragma = Pragma::IntegrityCheck(None);
907 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA integrity_check");
908 ///
909 /// // Check specific table
910 /// let pragma = Pragma::IntegrityCheck(Some("users"));
911 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA integrity_check(users)");
912 /// ```
913 IntegrityCheck(Option<&'static str>),
914
915 /// Perform faster database integrity check
916 ///
917 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_quick_check)
918 ///
919 /// # Example
920 /// ```
921 /// # use drizzle_sqlite::pragma::Pragma;
922 /// # use drizzle_core::ToSQL;
923 /// let pragma = Pragma::QuickCheck(None);
924 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA quick_check");
925 ///
926 /// let pragma = Pragma::QuickCheck(Some("users"));
927 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA quick_check(users)");
928 /// ```
929 QuickCheck(Option<&'static str>),
930
931 /// Attempt to optimize the database
932 ///
933 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_optimize)
934 ///
935 /// # Example
936 /// ```
937 /// # use drizzle_sqlite::pragma::Pragma;
938 /// # use drizzle_core::ToSQL;
939 /// let pragma = Pragma::Optimize(None);
940 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA optimize");
941 ///
942 /// let pragma = Pragma::Optimize(Some(0x10002));
943 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA optimize(65538)");
944 /// ```
945 Optimize(Option<u32>),
946
947 /// Check foreign key constraints for a table
948 ///
949 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_foreign_key_check)
950 ///
951 /// # Example
952 /// ```
953 /// # use drizzle_sqlite::pragma::Pragma;
954 /// # use drizzle_core::ToSQL;
955 /// let pragma = Pragma::ForeignKeyCheck(None);
956 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_key_check");
957 ///
958 /// let pragma = Pragma::ForeignKeyCheck(Some("orders"));
959 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_key_check(orders)");
960 /// ```
961 ForeignKeyCheck(Option<&'static str>),
962
963 // Table-specific Pragmas
964 /// Return information about table columns
965 ///
966 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_table_info)
967 ///
968 /// # Example
969 /// ```
970 /// # use drizzle_sqlite::pragma::Pragma;
971 /// # use drizzle_core::ToSQL;
972 /// let pragma = Pragma::TableInfo("users");
973 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA table_info(users)");
974 /// ```
975 TableInfo(&'static str),
976
977 /// Return information about table indexes
978 ///
979 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_index_list)
980 ///
981 /// # Example
982 /// ```
983 /// # use drizzle_sqlite::pragma::Pragma;
984 /// # use drizzle_core::ToSQL;
985 /// let pragma = Pragma::IndexList("users");
986 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA index_list(users)");
987 /// ```
988 IndexList(&'static str),
989
990 /// Return information about index columns
991 ///
992 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_index_info)
993 ///
994 /// # Example
995 /// ```
996 /// # use drizzle_sqlite::pragma::Pragma;
997 /// # use drizzle_core::ToSQL;
998 /// let pragma = Pragma::IndexInfo("idx_users_email");
999 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA index_info(idx_users_email)");
1000 /// ```
1001 IndexInfo(&'static str),
1002
1003 /// Return extended information about index columns
1004 ///
1005 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_index_xinfo)
1006 IndexXInfo(&'static str),
1007
1008 /// Return foreign key information for a table
1009 ///
1010 /// [SQLite Documentation](https://sqlite.org/pragma.html#pragma_foreign_key_list)
1011 ///
1012 /// # Example
1013 /// ```
1014 /// # use drizzle_sqlite::pragma::Pragma;
1015 /// # use drizzle_core::ToSQL;
1016 /// let pragma = Pragma::ForeignKeyList("orders");
1017 /// assert_eq!(pragma.to_sql().sql(), "PRAGMA foreign_key_list(orders)");
1018 /// ```
1019 ForeignKeyList(&'static str),
1020}
1021
1022impl<'a> ToSQL<'a, SQLiteValue<'a>> for AutoVacuum {
1023 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1024 match self {
1025 AutoVacuum::None => SQL::raw("NONE"),
1026 AutoVacuum::Full => SQL::raw("FULL"),
1027 AutoVacuum::Incremental => SQL::raw("INCREMENTAL"),
1028 }
1029 }
1030}
1031
1032impl<'a> ToSQL<'a, SQLiteValue<'a>> for JournalMode {
1033 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1034 match self {
1035 JournalMode::Delete => SQL::raw("DELETE"),
1036 JournalMode::Truncate => SQL::raw("TRUNCATE"),
1037 JournalMode::Persist => SQL::raw("PERSIST"),
1038 JournalMode::Memory => SQL::raw("MEMORY"),
1039 JournalMode::Wal => SQL::raw("WAL"),
1040 JournalMode::Off => SQL::raw("OFF"),
1041 }
1042 }
1043}
1044
1045impl<'a> ToSQL<'a, SQLiteValue<'a>> for Synchronous {
1046 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1047 match self {
1048 Synchronous::Off => SQL::raw("OFF"),
1049 Synchronous::Normal => SQL::raw("NORMAL"),
1050 Synchronous::Full => SQL::raw("FULL"),
1051 Synchronous::Extra => SQL::raw("EXTRA"),
1052 }
1053 }
1054}
1055
1056impl<'a> ToSQL<'a, SQLiteValue<'a>> for TempStore {
1057 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1058 match self {
1059 TempStore::Default => SQL::raw("DEFAULT"),
1060 TempStore::File => SQL::raw("FILE"),
1061 TempStore::Memory => SQL::raw("MEMORY"),
1062 }
1063 }
1064}
1065
1066impl<'a> ToSQL<'a, SQLiteValue<'a>> for LockingMode {
1067 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1068 match self {
1069 LockingMode::Normal => SQL::raw("NORMAL"),
1070 LockingMode::Exclusive => SQL::raw("EXCLUSIVE"),
1071 }
1072 }
1073}
1074
1075impl<'a> ToSQL<'a, SQLiteValue<'a>> for SecureDelete {
1076 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1077 match self {
1078 SecureDelete::Off => SQL::raw("OFF"),
1079 SecureDelete::On => SQL::raw("ON"),
1080 SecureDelete::Fast => SQL::raw("FAST"),
1081 }
1082 }
1083}
1084
1085impl<'a> ToSQL<'a, SQLiteValue<'a>> for Encoding {
1086 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1087 match self {
1088 Encoding::Utf8 => SQL::raw("UTF-8"),
1089 Encoding::Utf16Le => SQL::raw("UTF-16LE"),
1090 Encoding::Utf16Be => SQL::raw("UTF-16BE"),
1091 }
1092 }
1093}
1094
1095impl<'a> ToSQL<'a, SQLiteValue<'a>> for CacheSpill {
1096 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1097 match self {
1098 CacheSpill::Enabled(enabled) => SQL::raw(if *enabled { "ON" } else { "OFF" }),
1099 CacheSpill::Pages(pages) => SQL::raw(format!("{}", pages)),
1100 }
1101 }
1102}
1103
1104impl<'a> ToSQL<'a, SQLiteValue<'a>> for WalCheckpointMode {
1105 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1106 match self {
1107 WalCheckpointMode::Passive => SQL::raw("PASSIVE"),
1108 WalCheckpointMode::Full => SQL::raw("FULL"),
1109 WalCheckpointMode::Restart => SQL::raw("RESTART"),
1110 WalCheckpointMode::Truncate => SQL::raw("TRUNCATE"),
1111 WalCheckpointMode::Noop => SQL::raw("NOOP"),
1112 }
1113 }
1114}
1115
1116impl<'a> ToSQL<'a, SQLiteValue<'a>> for WritableSchema {
1117 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1118 match self {
1119 WritableSchema::Enabled(enabled) => SQL::raw(if *enabled { "ON" } else { "OFF" }),
1120 WritableSchema::Reset => SQL::raw("RESET"),
1121 }
1122 }
1123}
1124
1125impl<'a> ToSQL<'a, SQLiteValue<'a>> for Pragma {
1126 fn to_sql(&self) -> SQL<'a, SQLiteValue<'a>> {
1127 match self {
1128 // Read/Write Configuration Pragmas
1129 Pragma::ApplicationId(id) => SQL::raw(format!("PRAGMA application_id = {}", id)),
1130 Pragma::AutoVacuum(mode) => SQL::raw("PRAGMA auto_vacuum = ").append(mode.to_sql()),
1131 Pragma::CacheSize(size) => SQL::raw(format!("PRAGMA cache_size = {}", size)),
1132 Pragma::ForeignKeys(enabled) => SQL::raw("PRAGMA foreign_keys = ")
1133 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1134 Pragma::JournalMode(mode) => SQL::raw("PRAGMA journal_mode = ").append(mode.to_sql()),
1135 Pragma::Synchronous(mode) => SQL::raw("PRAGMA synchronous = ").append(mode.to_sql()),
1136 Pragma::WalAutocheckpoint(pages) => {
1137 SQL::raw(format!("PRAGMA wal_autocheckpoint = {}", pages))
1138 }
1139 Pragma::TempStore(store) => SQL::raw("PRAGMA temp_store = ").append(store.to_sql()),
1140 Pragma::LockingMode(mode) => SQL::raw("PRAGMA locking_mode = ").append(mode.to_sql()),
1141 Pragma::SecureDelete(mode) => SQL::raw("PRAGMA secure_delete = ").append(mode.to_sql()),
1142 Pragma::UserVersion(version) => SQL::raw(format!("PRAGMA user_version = {}", version)),
1143 Pragma::Encoding(encoding) => SQL::raw("PRAGMA encoding = ").append(encoding.to_sql()),
1144 Pragma::PageSize(size) => SQL::raw(format!("PRAGMA page_size = {}", size)),
1145 Pragma::MmapSize(size) => SQL::raw(format!("PRAGMA mmap_size = {}", size)),
1146 Pragma::RecursiveTriggers(enabled) => SQL::raw("PRAGMA recursive_triggers = ")
1147 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1148 Pragma::AnalysisLimit(limit) => SQL::raw(format!("PRAGMA analysis_limit = {}", limit)),
1149 Pragma::AutomaticIndex(enabled) => SQL::raw("PRAGMA automatic_index = ")
1150 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1151 Pragma::BusyTimeout(timeout) => SQL::raw(format!("PRAGMA busy_timeout = {}", timeout)),
1152 Pragma::CacheSpill(setting) => {
1153 SQL::raw("PRAGMA cache_spill = ").append(setting.to_sql())
1154 }
1155 Pragma::CaseSensitiveLike(enabled) => SQL::raw("PRAGMA case_sensitive_like = ")
1156 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1157 Pragma::CellSizeCheck(enabled) => SQL::raw("PRAGMA cell_size_check = ")
1158 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1159 Pragma::CheckpointFullFsync(enabled) => SQL::raw("PRAGMA checkpoint_fullfsync = ")
1160 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1161 Pragma::CountChanges(enabled) => SQL::raw("PRAGMA count_changes = ")
1162 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1163 Pragma::DataStoreDirectory(directory) => {
1164 SQL::raw(format!("PRAGMA data_store_directory = '{}'", directory))
1165 }
1166 Pragma::DefaultCacheSize(size) => {
1167 SQL::raw(format!("PRAGMA default_cache_size = {}", size))
1168 }
1169 Pragma::DeferForeignKeys(enabled) => SQL::raw("PRAGMA defer_foreign_keys = ")
1170 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1171 Pragma::EmptyResultCallbacks(enabled) => SQL::raw("PRAGMA empty_result_callbacks = ")
1172 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1173 Pragma::FullColumnNames(enabled) => SQL::raw("PRAGMA full_column_names = ")
1174 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1175 Pragma::FullFsync(enabled) => SQL::raw("PRAGMA fullfsync = ")
1176 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1177 Pragma::HardHeapLimit(limit) => SQL::raw(format!("PRAGMA hard_heap_limit = {}", limit)),
1178 Pragma::IgnoreCheckConstraints(enabled) => {
1179 SQL::raw("PRAGMA ignore_check_constraints = ").append(SQL::raw(if *enabled {
1180 "ON"
1181 } else {
1182 "OFF"
1183 }))
1184 }
1185 Pragma::JournalSizeLimit(limit) => {
1186 SQL::raw(format!("PRAGMA journal_size_limit = {}", limit))
1187 }
1188 Pragma::LegacyAlterTable(enabled) => SQL::raw("PRAGMA legacy_alter_table = ")
1189 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1190 Pragma::LegacyFileFormat => SQL::raw("PRAGMA legacy_file_format"),
1191 Pragma::MaxPageCount(count) => SQL::raw(format!("PRAGMA max_page_count = {}", count)),
1192 Pragma::QueryOnly(enabled) => SQL::raw("PRAGMA query_only = ")
1193 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1194 Pragma::ReadUncommitted(enabled) => SQL::raw("PRAGMA read_uncommitted = ")
1195 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1196 Pragma::ReverseUnorderedSelects(enabled) => {
1197 SQL::raw("PRAGMA reverse_unordered_selects = ").append(SQL::raw(if *enabled {
1198 "ON"
1199 } else {
1200 "OFF"
1201 }))
1202 }
1203 Pragma::SchemaVersion(version) => {
1204 SQL::raw(format!("PRAGMA schema_version = {}", version))
1205 }
1206 Pragma::ShortColumnNames(enabled) => SQL::raw("PRAGMA short_column_names = ")
1207 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1208 Pragma::SoftHeapLimit(limit) => SQL::raw(format!("PRAGMA soft_heap_limit = {}", limit)),
1209 Pragma::TempStoreDirectory(directory) => {
1210 SQL::raw(format!("PRAGMA temp_store_directory = '{}'", directory))
1211 }
1212 Pragma::Threads(threads) => SQL::raw(format!("PRAGMA threads = {}", threads)),
1213 Pragma::TrustedSchema(enabled) => SQL::raw("PRAGMA trusted_schema = ")
1214 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1215 Pragma::WritableSchema(mode) => {
1216 SQL::raw("PRAGMA writable_schema = ").append(mode.to_sql())
1217 }
1218 Pragma::ParserTrace(enabled) => SQL::raw("PRAGMA parser_trace = ")
1219 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1220 Pragma::VdbeAddoptrace(enabled) => SQL::raw("PRAGMA vdbe_addoptrace = ")
1221 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1222 Pragma::VdbeDebug(enabled) => SQL::raw("PRAGMA vdbe_debug = ")
1223 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1224 Pragma::VdbeListing(enabled) => SQL::raw("PRAGMA vdbe_listing = ")
1225 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1226 Pragma::VdbeTrace(enabled) => SQL::raw("PRAGMA vdbe_trace = ")
1227 .append(SQL::raw(if *enabled { "ON" } else { "OFF" })),
1228
1229 // Read-Only Query Pragmas
1230 Pragma::CollationList => SQL::raw("PRAGMA collation_list"),
1231 Pragma::CompileOptions => SQL::raw("PRAGMA compile_options"),
1232 Pragma::DatabaseList => SQL::raw("PRAGMA database_list"),
1233 Pragma::FunctionList => SQL::raw("PRAGMA function_list"),
1234 Pragma::TableList => SQL::raw("PRAGMA table_list"),
1235 Pragma::TableXInfo(table) => SQL::raw(format!("PRAGMA table_xinfo({})", table)),
1236 Pragma::ModuleList => SQL::raw("PRAGMA module_list"),
1237 Pragma::DataVersion => SQL::raw("PRAGMA data_version"),
1238 Pragma::FreelistCount => SQL::raw("PRAGMA freelist_count"),
1239 Pragma::PageCount => SQL::raw("PRAGMA page_count"),
1240 Pragma::PragmaList => SQL::raw("PRAGMA pragma_list"),
1241 Pragma::Stats => SQL::raw("PRAGMA stats"),
1242
1243 // Utility Pragmas
1244 Pragma::IncrementalVacuum(pages) => match pages {
1245 Some(count) => SQL::raw(format!("PRAGMA incremental_vacuum({})", count)),
1246 None => SQL::raw("PRAGMA incremental_vacuum"),
1247 },
1248 Pragma::ShrinkMemory => SQL::raw("PRAGMA shrink_memory"),
1249 Pragma::WalCheckpoint(mode) => match mode {
1250 Some(checkpoint_mode) => {
1251 SQL::raw("PRAGMA wal_checkpoint = ").append(checkpoint_mode.to_sql())
1252 }
1253 None => SQL::raw("PRAGMA wal_checkpoint"),
1254 },
1255 Pragma::IntegrityCheck(table) => match table {
1256 Some(t) => SQL::raw(format!("PRAGMA integrity_check({})", t)),
1257 None => SQL::raw("PRAGMA integrity_check"),
1258 },
1259 Pragma::QuickCheck(table) => match table {
1260 Some(t) => SQL::raw(format!("PRAGMA quick_check({})", t)),
1261 None => SQL::raw("PRAGMA quick_check"),
1262 },
1263 Pragma::Optimize(mask) => match mask {
1264 Some(m) => SQL::raw(format!("PRAGMA optimize({})", m)),
1265 None => SQL::raw("PRAGMA optimize"),
1266 },
1267 Pragma::ForeignKeyCheck(table) => match table {
1268 Some(t) => SQL::raw(format!("PRAGMA foreign_key_check({})", t)),
1269 None => SQL::raw("PRAGMA foreign_key_check"),
1270 },
1271
1272 // Table-specific Pragmas
1273 Pragma::TableInfo(table) => SQL::raw(format!("PRAGMA table_info({})", table)),
1274 Pragma::IndexList(table) => SQL::raw(format!("PRAGMA index_list({})", table)),
1275 Pragma::IndexInfo(index) => SQL::raw(format!("PRAGMA index_info({})", index)),
1276 Pragma::IndexXInfo(index) => SQL::raw(format!("PRAGMA index_xinfo({})", index)),
1277 Pragma::ForeignKeyList(table) => {
1278 SQL::raw(format!("PRAGMA foreign_key_list({})", table))
1279 }
1280 }
1281 }
1282}
1283
1284impl Pragma {
1285 /// Create a PRAGMA query to get the current value (read-only operation)
1286 pub fn query(pragma_name: &str) -> SQL<'static, SQLiteValue<'static>> {
1287 SQL::raw(format!("PRAGMA {}", pragma_name))
1288 }
1289
1290 /// Convenience constructor for foreign_keys pragma
1291 pub fn foreign_keys(enabled: bool) -> Self {
1292 Self::ForeignKeys(enabled)
1293 }
1294
1295 /// Convenience constructor for journal_mode pragma
1296 pub fn journal_mode(mode: JournalMode) -> Self {
1297 Self::JournalMode(mode)
1298 }
1299
1300 /// Convenience constructor for wal_autocheckpoint pragma
1301 pub fn wal_autocheckpoint(pages: i32) -> Self {
1302 Self::WalAutocheckpoint(pages)
1303 }
1304
1305 /// Convenience constructor for table_info pragma
1306 pub fn table_info(table: &'static str) -> Self {
1307 Self::TableInfo(table)
1308 }
1309
1310 /// Convenience constructor for index_list pragma
1311 pub fn index_list(table: &'static str) -> Self {
1312 Self::IndexList(table)
1313 }
1314
1315 /// Convenience constructor for foreign_key_list pragma
1316 pub fn foreign_key_list(table: &'static str) -> Self {
1317 Self::ForeignKeyList(table)
1318 }
1319
1320 /// Convenience constructor for integrity_check pragma
1321 pub fn integrity_check(table: Option<&'static str>) -> Self {
1322 Self::IntegrityCheck(table)
1323 }
1324
1325 /// Convenience constructor for foreign_key_check pragma
1326 pub fn foreign_key_check(table: Option<&'static str>) -> Self {
1327 Self::ForeignKeyCheck(table)
1328 }
1329
1330 /// Convenience constructor for table_xinfo pragma
1331 pub fn table_xinfo(table: &'static str) -> Self {
1332 Self::TableXInfo(table)
1333 }
1334
1335 /// Convenience constructor for encoding pragma
1336 pub fn encoding(encoding: Encoding) -> Self {
1337 Self::Encoding(encoding)
1338 }
1339}
1340
1341#[cfg(test)]
1342mod tests {
1343 use super::*;
1344
1345 #[test]
1346 fn test_query_pragma_helper() {
1347 // Test the static query helper function - not covered in doc tests
1348 assert_eq!(Pragma::query("foreign_keys").sql(), "PRAGMA foreign_keys");
1349 assert_eq!(Pragma::query("custom_pragma").sql(), "PRAGMA custom_pragma");
1350 }
1351
1352 #[test]
1353 fn test_convenience_constructor_integration() {
1354 // Test that convenience constructors work the same as direct construction
1355 assert_eq!(
1356 Pragma::foreign_keys(true).to_sql().sql(),
1357 Pragma::ForeignKeys(true).to_sql().sql()
1358 );
1359 assert_eq!(
1360 Pragma::table_info("users").to_sql().sql(),
1361 Pragma::TableInfo("users").to_sql().sql()
1362 );
1363 assert_eq!(
1364 Pragma::encoding(Encoding::Utf8).to_sql().sql(),
1365 Pragma::Encoding(Encoding::Utf8).to_sql().sql()
1366 );
1367 }
1368}