sqlx_rxqlite/types/
bool.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 bool {
9    fn type_info() -> RXQLiteTypeInfo {
10        RXQLiteTypeInfo(DataType::Bool)
11    }
12
13    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
14        matches!(ty.0, DataType::Bool | DataType::Int | DataType::Int64)
15    }
16}
17
18impl<'q> Encode<'q, RXQLite> for bool {
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 bool {
27    fn decode(value: RXQLiteValueRef<'r>) -> Result<bool, BoxDynError> {
28        Ok(value.int()? != 0)
29    }
30}