mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 05:54:21 +01:00
use strum package to simplify PragmaName enum management
The pragma list will only grow. The strum crate can be used to: * automatically convert to string from enum * automatically convert to enum from string * implement an iterator over all elements of the enum
This commit is contained in:
@@ -7,6 +7,8 @@ use std::num::ParseIntError;
|
||||
use std::ops::Deref;
|
||||
use std::str::{self, Bytes, FromStr};
|
||||
|
||||
use strum_macros::{EnumIter, EnumString};
|
||||
|
||||
use fmt::{ToTokens, TokenStream};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
@@ -1585,7 +1587,8 @@ pub type PragmaValue = Expr; // TODO
|
||||
|
||||
/// `PRAGMA` value
|
||||
// https://sqlite.org/pragma.html
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, EnumString, strum::Display)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum PragmaName {
|
||||
/// `cache_size` pragma
|
||||
CacheSize,
|
||||
@@ -1597,20 +1600,6 @@ pub enum PragmaName {
|
||||
TableInfo,
|
||||
}
|
||||
|
||||
impl FromStr for PragmaName {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||
match input {
|
||||
"cache_size" => Ok(PragmaName::CacheSize),
|
||||
"wal_checkpoint" => Ok(PragmaName::WalCheckpoint),
|
||||
"journal_mode" => Ok(PragmaName::JournalMode),
|
||||
"table_info" => Ok(PragmaName::TableInfo),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `CREATE TRIGGER` time
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum TriggerTime {
|
||||
|
||||
Reference in New Issue
Block a user