|
@@ -1,22 +1,60 @@
|
|
|
use super::Modelable;
|
|
|
use sqlite::Bindable;
|
|
|
|
|
|
-impl Modelable for i32 {
|
|
|
+macro_rules! integral {
|
|
|
+ ($i:ty) => {
|
|
|
+ impl Modelable for $i {
|
|
|
+ fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
+ (*self as i64).bind(stmt, col)
|
|
|
+ }
|
|
|
+ fn build_from(stmt: &sqlite::Statement, col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
+ where
|
|
|
+ Self: Sized,
|
|
|
+ {
|
|
|
+ stmt.read::<i64>(col_offset).map(|x| (x as Self, 1))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+integral!(i8);
|
|
|
+integral!(u8);
|
|
|
+integral!(i16);
|
|
|
+integral!(u16);
|
|
|
+integral!(i32);
|
|
|
+integral!(u32);
|
|
|
+integral!(i64);
|
|
|
+integral!(u64);
|
|
|
+
|
|
|
+impl Modelable for bool {
|
|
|
fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
- (*self as i64).bind(stmt, col)
|
|
|
+ let val = if self == &true { 1i64 } else { 0i64 };
|
|
|
+ val.bind(stmt, col)
|
|
|
}
|
|
|
- fn build_from(stmt: &sqlite::Statement, col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
+ fn build_from(_stmt: &sqlite::Statement, _col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
where
|
|
|
Self: Sized,
|
|
|
{
|
|
|
- stmt.read::<i64>(col_offset).map(|x| (x as i32, 1))
|
|
|
+ unreachable!("sqlite only gives Strings back, not &strs!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl Modelable for i64 {
|
|
|
+impl<'a> Modelable for &'a str {
|
|
|
fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
self.bind(stmt, col)
|
|
|
}
|
|
|
+ fn build_from(_stmt: &sqlite::Statement, _col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
+ where
|
|
|
+ Self: Sized,
|
|
|
+ {
|
|
|
+ unreachable!("sqlite only gives Strings back, not &strs!");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Modelable for std::string::String {
|
|
|
+ fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
+ self.as_str().bind(stmt, col)
|
|
|
+ }
|
|
|
fn build_from(stmt: &sqlite::Statement, col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
where
|
|
|
Self: Sized,
|
|
@@ -25,7 +63,7 @@ impl Modelable for i64 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<'a> Modelable for &'a str {
|
|
|
+impl<'a> Modelable for &'a [u8] {
|
|
|
fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
self.bind(stmt, col)
|
|
|
}
|
|
@@ -33,13 +71,13 @@ impl<'a> Modelable for &'a str {
|
|
|
where
|
|
|
Self: Sized,
|
|
|
{
|
|
|
- unreachable!("sqlite only gives Strings back, not &strs!");
|
|
|
+ unreachable!("sqlite only gives Vec<u8> back, not &[u8]!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl Modelable for std::string::String {
|
|
|
+impl Modelable for Vec<u8> {
|
|
|
fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
|
|
|
- self.as_str().bind(stmt, col)
|
|
|
+ self.bind(stmt, col)
|
|
|
}
|
|
|
fn build_from(stmt: &sqlite::Statement, col_offset: usize) -> sqlite::Result<(Self, usize)>
|
|
|
where
|