Skip to content

Commit

Permalink
add FromStr, Copy, PartialEq, Eq impls for sqlite options (#1784)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
  • Loading branch information
andrewwhitehead authored Apr 5, 2022
1 parent f4ed7e6 commit 040eb77
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
23 changes: 22 additions & 1 deletion sqlx-core/src/sqlite/options/auto_vacuum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[derive(Debug, Clone)]
use crate::error::Error;
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SqliteAutoVacuum {
None,
Full,
Expand All @@ -20,3 +23,21 @@ impl Default for SqliteAutoVacuum {
SqliteAutoVacuum::None
}
}

impl FromStr for SqliteAutoVacuum {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
Ok(match &*s.to_ascii_lowercase() {
"none" => SqliteAutoVacuum::None,
"full" => SqliteAutoVacuum::Full,
"incremental" => SqliteAutoVacuum::Incremental,

_ => {
return Err(Error::Configuration(
format!("unknown value {:?} for `auto_vacuum`", s).into(),
));
}
})
}
}
5 changes: 4 additions & 1 deletion sqlx-core/src/sqlite/options/journal_mode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::error::Error;
use std::str::FromStr;

#[derive(Debug, Clone)]
/// Refer to [SQLite documentation] for the meaning of the database journaling mode.
///
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_journal_mode
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SqliteJournalMode {
Delete,
Truncate,
Expand Down
25 changes: 24 additions & 1 deletion sqlx-core/src/sqlite/options/locking_mode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#[derive(Debug, Clone)]
use crate::error::Error;
use std::str::FromStr;

/// Refer to [SQLite documentation] for the meaning of the connection locking mode.
///
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_locking_mode
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SqliteLockingMode {
Normal,
Exclusive,
Expand All @@ -18,3 +24,20 @@ impl Default for SqliteLockingMode {
SqliteLockingMode::Normal
}
}

impl FromStr for SqliteLockingMode {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
Ok(match &*s.to_ascii_lowercase() {
"normal" => SqliteLockingMode::Normal,
"exclusive" => SqliteLockingMode::Exclusive,

_ => {
return Err(Error::Configuration(
format!("unknown value {:?} for `locking_mode`", s).into(),
));
}
})
}
}
2 changes: 1 addition & 1 deletion sqlx-core/src/sqlite/options/synchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;
/// Refer to [SQLite documentation] for the meaning of various synchronous settings.
///
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_synchronous
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SqliteSynchronous {
Off,
Normal,
Expand Down

0 comments on commit 040eb77

Please sign in to comment.