sqlx_core/sqlite/options/
synchronous.rs

1use crate::error::Error;
2use std::str::FromStr;
3
4/// Refer to [SQLite documentation] for the meaning of various synchronous settings.
5///
6/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_synchronous
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum SqliteSynchronous {
9    Off,
10    Normal,
11    Full,
12    Extra,
13}
14
15impl SqliteSynchronous {
16    pub(crate) fn as_str(&self) -> &'static str {
17        match self {
18            SqliteSynchronous::Off => "OFF",
19            SqliteSynchronous::Normal => "NORMAL",
20            SqliteSynchronous::Full => "FULL",
21            SqliteSynchronous::Extra => "EXTRA",
22        }
23    }
24}
25
26impl Default for SqliteSynchronous {
27    fn default() -> Self {
28        SqliteSynchronous::Full
29    }
30}
31
32impl FromStr for SqliteSynchronous {
33    type Err = Error;
34
35    fn from_str(s: &str) -> Result<Self, Error> {
36        Ok(match &*s.to_ascii_lowercase() {
37            "off" => SqliteSynchronous::Off,
38            "normal" => SqliteSynchronous::Normal,
39            "full" => SqliteSynchronous::Full,
40            "extra" => SqliteSynchronous::Extra,
41
42            _ => {
43                return Err(Error::Configuration(
44                    format!("unknown value {:?} for `synchronous`", s).into(),
45                ));
46            }
47        })
48    }
49}