sqlx_sqlite/options/
locking_mode.rs

1use crate::error::Error;
2use std::str::FromStr;
3
4/// Refer to [SQLite documentation] for the meaning of the connection locking mode.
5///
6/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_locking_mode
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8pub enum SqliteLockingMode {
9    #[default]
10    Normal,
11    Exclusive,
12}
13
14impl SqliteLockingMode {
15    pub(crate) fn as_str(&self) -> &'static str {
16        match self {
17            SqliteLockingMode::Normal => "NORMAL",
18            SqliteLockingMode::Exclusive => "EXCLUSIVE",
19        }
20    }
21}
22
23impl FromStr for SqliteLockingMode {
24    type Err = Error;
25
26    fn from_str(s: &str) -> Result<Self, Error> {
27        Ok(match &*s.to_ascii_lowercase() {
28            "normal" => SqliteLockingMode::Normal,
29            "exclusive" => SqliteLockingMode::Exclusive,
30
31            _ => {
32                return Err(Error::Configuration(
33                    format!("unknown value {s:?} for `locking_mode`").into(),
34                ));
35            }
36        })
37    }
38}