Skip to content

Commit 040eb77

Browse files
add FromStr, Copy, PartialEq, Eq impls for sqlite options (#1784)
Signed-off-by: Andrew Whitehead <[email protected]>
1 parent f4ed7e6 commit 040eb77

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

sqlx-core/src/sqlite/options/auto_vacuum.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#[derive(Debug, Clone)]
1+
use crate::error::Error;
2+
use std::str::FromStr;
3+
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25
pub enum SqliteAutoVacuum {
36
None,
47
Full,
@@ -20,3 +23,21 @@ impl Default for SqliteAutoVacuum {
2023
SqliteAutoVacuum::None
2124
}
2225
}
26+
27+
impl FromStr for SqliteAutoVacuum {
28+
type Err = Error;
29+
30+
fn from_str(s: &str) -> Result<Self, Error> {
31+
Ok(match &*s.to_ascii_lowercase() {
32+
"none" => SqliteAutoVacuum::None,
33+
"full" => SqliteAutoVacuum::Full,
34+
"incremental" => SqliteAutoVacuum::Incremental,
35+
36+
_ => {
37+
return Err(Error::Configuration(
38+
format!("unknown value {:?} for `auto_vacuum`", s).into(),
39+
));
40+
}
41+
})
42+
}
43+
}

sqlx-core/src/sqlite/options/journal_mode.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use crate::error::Error;
22
use std::str::FromStr;
33

4-
#[derive(Debug, Clone)]
4+
/// Refer to [SQLite documentation] for the meaning of the database journaling mode.
5+
///
6+
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_journal_mode
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58
pub enum SqliteJournalMode {
69
Delete,
710
Truncate,

sqlx-core/src/sqlite/options/locking_mode.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#[derive(Debug, Clone)]
1+
use crate::error::Error;
2+
use 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)]
28
pub enum SqliteLockingMode {
39
Normal,
410
Exclusive,
@@ -18,3 +24,20 @@ impl Default for SqliteLockingMode {
1824
SqliteLockingMode::Normal
1925
}
2026
}
27+
28+
impl 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+
}

sqlx-core/src/sqlite/options/synchronous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44
/// Refer to [SQLite documentation] for the meaning of various synchronous settings.
55
///
66
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_synchronous
7-
#[derive(Debug, Clone)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88
pub enum SqliteSynchronous {
99
Off,
1010
Normal,

0 commit comments

Comments
 (0)