sqlx_sqlite/options/
journal_mode.rs1use crate::error::Error;
2use std::str::FromStr;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8pub enum SqliteJournalMode {
9 Delete,
10 Truncate,
11 Persist,
12 Memory,
13 #[default]
14 Wal,
15 Off,
16}
17
18impl SqliteJournalMode {
19 pub(crate) fn as_str(&self) -> &'static str {
20 match self {
21 SqliteJournalMode::Delete => "DELETE",
22 SqliteJournalMode::Truncate => "TRUNCATE",
23 SqliteJournalMode::Persist => "PERSIST",
24 SqliteJournalMode::Memory => "MEMORY",
25 SqliteJournalMode::Wal => "WAL",
26 SqliteJournalMode::Off => "OFF",
27 }
28 }
29}
30
31impl FromStr for SqliteJournalMode {
32 type Err = Error;
33
34 fn from_str(s: &str) -> Result<Self, Error> {
35 Ok(match &*s.to_ascii_lowercase() {
36 "delete" => SqliteJournalMode::Delete,
37 "truncate" => SqliteJournalMode::Truncate,
38 "persist" => SqliteJournalMode::Persist,
39 "memory" => SqliteJournalMode::Memory,
40 "wal" => SqliteJournalMode::Wal,
41 "off" => SqliteJournalMode::Off,
42
43 _ => {
44 return Err(Error::Configuration(
45 format!("unknown value {s:?} for `journal_mode`").into(),
46 ));
47 }
48 })
49 }
50}