cdbc_sqlite/types/
bool.rs1use cdbc::decode::Decode;
2use cdbc::encode::{Encode, IsNull};
3use cdbc::error::BoxDynError;
4use crate::type_info::DataType;
5use crate::{Sqlite, SqliteArgumentValue, SqliteTypeInfo, SqliteValueRef};
6use cdbc::types::Type;
7
8impl Type<Sqlite> for bool {
9 fn type_info() -> SqliteTypeInfo {
10 SqliteTypeInfo(DataType::Bool)
11 }
12
13 fn compatible(ty: &SqliteTypeInfo) -> bool {
14 matches!(ty.0, DataType::Bool | DataType::Int | DataType::Int64)
15 }
16}
17
18impl<'q> Encode<'q, Sqlite> for bool {
19 fn encode_by_ref(&self, args: &mut Vec<SqliteArgumentValue<'q>>) -> IsNull {
20 args.push(SqliteArgumentValue::Int((*self).into()));
21
22 IsNull::No
23 }
24}
25
26impl<'r> Decode<'r, Sqlite> for bool {
27 fn decode(value: SqliteValueRef<'r>) -> Result<bool, BoxDynError> {
28 Ok(value.int() != 0)
29 }
30}