persistant_relational/
value.rs1use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6#[non_exhaustive]
7pub enum Dialect {
8 Postgres,
10 Sqlite,
12 MySql,
14 MariaDb,
16 Other(String),
18}
19
20impl fmt::Display for Dialect {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Dialect::Postgres => f.write_str("postgres"),
24 Dialect::Sqlite => f.write_str("sqlite"),
25 Dialect::MySql => f.write_str("mysql"),
26 Dialect::MariaDb => f.write_str("mariadb"),
27 Dialect::Other(n) => f.write_str(n),
28 }
29 }
30}
31
32#[derive(Debug, Clone, PartialEq)]
35#[non_exhaustive]
36pub enum Value {
37 Null,
39 Bool(bool),
41 Int(i64),
43 Float(f64),
45 Text(String),
47 Bytes(Vec<u8>),
49}
50
51#[derive(Debug, Clone, PartialEq)]
53pub struct Row {
54 pub values: Vec<Value>,
56}
57
58impl Row {
59 pub fn new(values: Vec<Value>) -> Self {
61 Row { values }
62 }
63
64 pub fn bytes(&self, i: usize) -> Option<&[u8]> {
66 match self.values.get(i) {
67 Some(Value::Bytes(b)) => Some(b),
68 _ => None,
69 }
70 }
71
72 pub fn int(&self, i: usize) -> Option<i64> {
74 match self.values.get(i) {
75 Some(Value::Int(n)) => Some(*n),
76 _ => None,
77 }
78 }
79
80 pub fn text(&self, i: usize) -> Option<&str> {
82 match self.values.get(i) {
83 Some(Value::Text(s)) => Some(s),
84 _ => None,
85 }
86 }
87}