sqlx_rxqlite/statement/
mod.rs1use 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#[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