lunatic_sqlite_api/wire_format/bind_values/
mod.rs

1use std::ops::Deref;
2
3use serde::{Deserialize, Serialize};
4
5#[cfg(not(target_arch = "wasm32"))]
6mod host_api;
7
8/// Struct used for binding a certain `BindValue` to either
9/// a numeric key or a named key in a prepared statement
10#[derive(Debug, Serialize, Deserialize)]
11pub enum BindKey {
12    /// Is encoded as 0x00
13    None,
14    /// Is encoded as 0x01
15    /// and uses a u32 for length of stream
16    /// which is stored as usize because the sqlite library needs usize
17    /// and this will save repeated conversions
18    Numeric(usize),
19    /// Is encoded as 0x02
20    /// indicates that a string is used as index for the bind value
21    String(String),
22}
23
24/// Represents a pair of BindKey and BindValue
25/// that are used to bind certain data to a prepared statement
26/// where BindKey is usually either a numeric index
27/// starting with 1 or a string.
28#[derive(Debug, Serialize, Deserialize)]
29pub struct BindPair(pub BindKey, pub BindValue);
30
31/// Enum that represents possible different
32/// types of values that can be bound to a prepared statements
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub enum BindValue {
35    Null,
36    Blob(Vec<u8>),
37    Text(String),
38    Double(f64),
39    Int(i32),
40    Int64(i64),
41}
42
43#[derive(Debug, Serialize, Deserialize)]
44pub struct BindList(pub Vec<BindPair>);
45
46impl Deref for BindList {
47    type Target = Vec<BindPair>;
48
49    fn deref(&self) -> &Self::Target {
50        &self.0
51    }
52}
53
54// ============================
55// Error structure
56// ============================
57/// Error structure that carries data from sqlite_errmsg and sqlite_errcode
58#[derive(Debug, Clone, Default, Serialize, Deserialize)]
59pub struct SqliteError {
60    pub code: Option<u32>,
61    pub message: Option<String>,
62}