sqlx_rxqlite/types/
int.rs

1use crate::decode::Decode;
2use crate::encode::{Encode, IsNull};
3use crate::error::BoxDynError;
4use crate::type_info::DataType;
5use crate::types::Type;
6use crate::{RXQLite, /*RXQLiteArgumentValue,*/ RXQLiteTypeInfo, RXQLiteValueRef};
7
8impl Type<RXQLite> for i8 {
9    fn type_info() -> RXQLiteTypeInfo {
10        RXQLiteTypeInfo(DataType::Int)
11    }
12
13    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
14        matches!(ty.0, DataType::Int | DataType::Int64)
15    }
16}
17
18impl<'q> Encode<'q, RXQLite> for i8 {
19    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
20        args.push(rxqlite_common::Value::Int((*self).into()));
21
22        IsNull::No
23    }
24}
25
26impl<'r> Decode<'r, RXQLite> for i8 {
27    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
28        Ok(value.int()?.try_into()?)
29    }
30}
31
32impl Type<RXQLite> for i16 {
33    fn type_info() -> RXQLiteTypeInfo {
34        RXQLiteTypeInfo(DataType::Int)
35    }
36
37    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
38        matches!(ty.0, DataType::Int | DataType::Int64)
39    }
40}
41
42impl<'q> Encode<'q, RXQLite> for i16 {
43    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
44        args.push(rxqlite_common::Value::Int((*self).into()));
45
46        IsNull::No
47    }
48}
49
50impl<'r> Decode<'r, RXQLite> for i16 {
51    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
52        Ok(value.int()?.try_into()?)
53    }
54}
55
56impl Type<RXQLite> for i32 {
57    fn type_info() -> RXQLiteTypeInfo {
58        RXQLiteTypeInfo(DataType::Int)
59    }
60
61    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
62        matches!(ty.0, DataType::Int | DataType::Int64)
63    }
64}
65
66impl<'q> Encode<'q, RXQLite> for i32 {
67    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
68        args.push(rxqlite_common::Value::Int((*self).into()));
69
70        IsNull::No
71    }
72}
73
74impl<'r> Decode<'r, RXQLite> for i32 {
75    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
76        Ok(value.int()?)
77    }
78}
79
80impl Type<RXQLite> for i64 {
81    fn type_info() -> RXQLiteTypeInfo {
82        RXQLiteTypeInfo(DataType::Int64)
83    }
84
85    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
86        matches!(ty.0, DataType::Int | DataType::Int64)
87    }
88}
89
90impl<'q> Encode<'q, RXQLite> for i64 {
91    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
92        args.push(rxqlite_common::Value::Int((*self).into()));
93
94        IsNull::No
95    }
96}
97
98impl<'r> Decode<'r, RXQLite> for i64 {
99    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
100        Ok(value.int64()?)
101    }
102}