sqlx_core_oldapi/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)]
8pub enum SqliteLockingMode {
9    Normal,
10    Exclusive,
11}
12
13impl SqliteLockingMode {
14    pub(crate) fn as_str(&self) -> &'static str {
15        match self {
16            SqliteLockingMode::Normal => "NORMAL",
17            SqliteLockingMode::Exclusive => "EXCLUSIVE",
18        }
19    }
20}
21
22impl Default for SqliteLockingMode {
23    fn default() -> Self {
24        SqliteLockingMode::Normal
25    }
26}
27
28impl FromStr for SqliteLockingMode {
29    type Err = Error;
30
31    fn from_str(s: &str) -> Result<Self, Error> {
32        Ok(match &*s.to_ascii_lowercase() {
33            "normal" => SqliteLockingMode::Normal,
34            "exclusive" => SqliteLockingMode::Exclusive,
35
36            _ => {
37                return Err(Error::Configuration(
38                    format!("unknown value {:?} for `locking_mode`", s).into(),
39                ));
40            }
41        })
42    }
43}