use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Dialect {
Postgres,
Sqlite,
MySql,
MariaDb,
Other(String),
}
impl fmt::Display for Dialect {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Dialect::Postgres => f.write_str("postgres"),
Dialect::Sqlite => f.write_str("sqlite"),
Dialect::MySql => f.write_str("mysql"),
Dialect::MariaDb => f.write_str("mariadb"),
Dialect::Other(n) => f.write_str(n),
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Text(String),
Bytes(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Row {
pub values: Vec<Value>,
}
impl Row {
pub fn new(values: Vec<Value>) -> Self {
Row { values }
}
pub fn bytes(&self, i: usize) -> Option<&[u8]> {
match self.values.get(i) {
Some(Value::Bytes(b)) => Some(b),
_ => None,
}
}
pub fn int(&self, i: usize) -> Option<i64> {
match self.values.get(i) {
Some(Value::Int(n)) => Some(*n),
_ => None,
}
}
pub fn text(&self, i: usize) -> Option<&str> {
match self.values.get(i) {
Some(Value::Text(s)) => Some(s),
_ => None,
}
}
}