Skip to content

Add FromStr, Copy, PartialEq, Eq impls for Sqlite options #1784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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