sqlx_sqlite/types/
bool.rs1use crate::decode::Decode;
2use crate::encode::{Encode, IsNull};
3use crate::error::BoxDynError;
4use crate::type_info::DataType;
5use crate::types::Type;
6use crate::{Sqlite, SqliteArgumentValue, SqliteTypeInfo, SqliteValueRef};
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::Int4 | DataType::Integer)
15 }
16}
17
18impl<'q> Encode<'q, Sqlite> for bool {
19 fn encode_by_ref(
20 &self,
21 args: &mut Vec<SqliteArgumentValue<'q>>,
22 ) -> Result<IsNull, BoxDynError> {
23 args.push(SqliteArgumentValue::Int((*self).into()));
24
25 Ok(IsNull::No)
26 }
27}
28
29impl<'r> Decode<'r, Sqlite> for bool {
30 fn decode(value: SqliteValueRef<'r>) -> Result<bool, BoxDynError> {
31 Ok(value.int64() != 0)
32 }
33}