typed_sql/types/
mod.rs

1use std::fmt::Write;
2
3pub mod bind;
4pub use bind::{Bind, Binding};
5
6pub mod field;
7pub use field::Field;
8
9pub trait Primitive {
10    fn write_primative(&self, sql: &mut String);
11}
12
13impl Primitive for String {
14    fn write_primative(&self, sql: &mut String) {
15        sql.push('\'');
16        sql.push_str(&self);
17        sql.push('\'');
18    }
19}
20
21impl Primitive for &'_ str {
22    fn write_primative(&self, sql: &mut String) {
23        sql.push('\'');
24        sql.push_str(self);
25        sql.push('\'');
26    }
27}
28
29impl Primitive for i64 {
30    fn write_primative(&self, sql: &mut String) {
31        sql.write_fmt(format_args!("{}", self)).unwrap();
32    }
33}
34
35impl<P: Primitive> Primitive for Option<P> {
36    fn write_primative(&self, sql: &mut String) {
37        if let Some(primative) = self {
38            primative.write_primative(sql);
39        } else {
40            sql.push_str("NULL");
41        }
42    }
43}