toasty_sql/stmt/
pragma.rs

1use super::Statement;
2
3/// A SQLite PRAGMA statement.
4#[derive(Debug, Clone)]
5pub struct Pragma {
6    /// The pragma name (e.g. "foreign_keys").
7    pub name: String,
8
9    /// The value to set, if any. When `None`, this is a query pragma.
10    pub value: Option<String>,
11}
12
13impl Statement {
14    /// Sets `PRAGMA foreign_keys = ON`.
15    pub fn pragma_enable_foreign_keys() -> Self {
16        Pragma {
17            name: "foreign_keys".to_string(),
18            value: Some("ON".to_string()),
19        }
20        .into()
21    }
22
23    /// Sets `PRAGMA foreign_keys = OFF`.
24    pub fn pragma_disable_foreign_keys() -> Self {
25        Pragma {
26            name: "foreign_keys".to_string(),
27            value: Some("OFF".to_string()),
28        }
29        .into()
30    }
31
32    /// Creates a PRAGMA statement with the given name and value.
33    pub fn pragma(name: impl Into<String>, value: impl Into<String>) -> Self {
34        Pragma {
35            name: name.into(),
36            value: Some(value.into()),
37        }
38        .into()
39    }
40}
41
42impl From<Pragma> for Statement {
43    fn from(value: Pragma) -> Self {
44        Self::Pragma(value)
45    }
46}