sqlx_rxqlite/statement/
mod.rs

1use crate::column::ColumnIndex;
2use crate::error::Error;
3use crate::{RXQLite, RXQLiteArguments, RXQLiteColumn, RXQLiteTypeInfo};
4use sqlx_core::ext::ustr::UStr;
5use sqlx_core::{Either, HashMap};
6use std::borrow::Cow;
7use std::sync::Arc;
8
9use sqlx_core::impl_statement_query;
10pub(crate) use sqlx_core::statement::*;
11/*
12mod handle;
13pub(super) mod unlock_notify;
14mod r#virtual;
15
16pub(crate) use handle::StatementHandle;
17pub(crate) use r#virtual::VirtualStatement;
18*/
19#[derive(Debug, Clone)]
20#[allow(clippy::rc_buffer)]
21pub struct RXQLiteStatement<'q> {
22    pub(crate) sql: Cow<'q, str>,
23    pub(crate) parameters: usize,
24    pub(crate) columns: Arc<Vec<RXQLiteColumn>>,
25    pub(crate) column_names: Arc<HashMap<UStr, usize>>,
26}
27
28impl<'q> Statement<'q> for RXQLiteStatement<'q> {
29    type Database = RXQLite;
30
31    fn to_owned(&self) -> RXQLiteStatement<'static> {
32        RXQLiteStatement::<'static> {
33            sql: Cow::Owned(self.sql.clone().into_owned()),
34            parameters: self.parameters,
35            columns: Arc::clone(&self.columns),
36            column_names: Arc::clone(&self.column_names),
37        }
38    }
39
40    fn sql(&self) -> &str {
41        &self.sql
42    }
43
44    fn parameters(&self) -> Option<Either<&[RXQLiteTypeInfo], usize>> {
45        Some(Either::Right(self.parameters))
46    }
47
48    fn columns(&self) -> &[RXQLiteColumn] {
49        &self.columns
50    }
51
52    impl_statement_query!(RXQLiteArguments);
53}
54
55impl ColumnIndex<RXQLiteStatement<'_>> for &'_ str {
56    fn index(&self, statement: &RXQLiteStatement<'_>) -> Result<usize, Error> {
57        statement
58            .column_names
59            .get(*self)
60            .ok_or_else(|| Error::ColumnNotFound((*self).into()))
61            .map(|v| *v)
62    }
63}
64
65// #[cfg(feature = "any")]
66// impl<'q> From<RXQLiteStatement<'q>> for crate::any::AnyStatement<'q> {
67//     #[inline]
68//     fn from(statement: RXQLiteStatement<'q>) -> Self {
69//         crate::any::AnyStatement::<'q> {
70//             columns: statement
71//                 .columns
72//                 .iter()
73//                 .map(|col| col.clone().into())
74//                 .collect(),
75//             column_names: statement.column_names,
76//             parameters: Some(Either::Right(statement.parameters)),
77//             sql: statement.sql,
78//         }
79//     }
80// }