rbdc_sqlite/types/
int.rs

1use crate::decode::Decode;
2use crate::encode::{Encode, IsNull};
3use crate::type_info::DataType;
4use crate::types::Type;
5use crate::{SqliteArgumentValue, SqliteTypeInfo, SqliteValue};
6use rbdc::error::Error;
7
8impl Type for i8 {
9    fn type_info(&self) -> SqliteTypeInfo {
10        SqliteTypeInfo(DataType::Int)
11    }
12}
13
14impl Encode for i8 {
15    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
16        args.push(SqliteArgumentValue::Int(self as i32));
17
18        Ok(IsNull::No)
19    }
20}
21
22impl Decode for i8 {
23    fn decode(value: SqliteValue) -> Result<Self, Error> {
24        Ok(value.int().try_into()?)
25    }
26}
27
28impl Type for i16 {
29    fn type_info(&self) -> SqliteTypeInfo {
30        SqliteTypeInfo(DataType::Int)
31    }
32}
33
34impl Encode for i16 {
35    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
36        args.push(SqliteArgumentValue::Int(self as i32));
37
38        Ok(IsNull::No)
39    }
40}
41
42impl Decode for i16 {
43    fn decode(value: SqliteValue) -> Result<Self, Error> {
44        Ok(value.int().try_into()?)
45    }
46}
47
48impl Type for i32 {
49    fn type_info(&self) -> SqliteTypeInfo {
50        SqliteTypeInfo(DataType::Int)
51    }
52}
53
54impl Encode for i32 {
55    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
56        args.push(SqliteArgumentValue::Int(self));
57
58        Ok(IsNull::No)
59    }
60}
61
62impl Decode for i32 {
63    fn decode(value: SqliteValue) -> Result<Self, Error> {
64        Ok(value.int())
65    }
66}
67
68impl Type for i64 {
69    fn type_info(&self) -> SqliteTypeInfo {
70        SqliteTypeInfo(DataType::Int64)
71    }
72}
73
74impl Encode for i64 {
75    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
76        args.push(SqliteArgumentValue::Int64(self));
77
78        Ok(IsNull::No)
79    }
80}
81
82impl Decode for i64 {
83    fn decode(value: SqliteValue) -> Result<Self, Error> {
84        Ok(value.int64())
85    }
86}