1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#![allow(clippy::rc_buffer)]
use std::sync::Arc;
use sqlx_core::column::ColumnIndex;
use sqlx_core::error::Error;
use sqlx_core::ext::ustr::UStr;
use sqlx_core::row::Row;
use sqlx_core::HashMap;
//use crate::statement::StatementHandle;
use crate::{Rqlite, RqliteColumn, RqliteValue, RqliteValueRef};
/// Implementation of [`Row`] for SQLite.
pub struct RqliteRow {
pub(crate) values: Box<[RqliteValue]>,
pub(crate) columns: Arc<Vec<RqliteColumn>>,
pub(crate) column_names: Arc<HashMap<UStr, usize>>,
}
// Accessing values from the statement object is
// safe across threads as long as we don't call [sqlite3_step]
// we block ourselves from doing that by only exposing
// a set interface on [StatementHandle]
//unsafe impl Send for RqliteRow {}
//unsafe impl Sync for RqliteRow {}
impl RqliteRow {
/*
pub(crate) fn current(
statement: &StatementHandle,
columns: &Arc<Vec<RqliteColumn>>,
column_names: &Arc<HashMap<UStr, usize>>,
) -> Self {
let size = statement.column_count();
let mut values = Vec::with_capacity(size);
for i in 0..size {
values.push(unsafe {
let raw = statement.column_value(i);
RqliteValue::new(raw, columns[i].type_info.clone())
});
}
Self {
values: values.into_boxed_slice(),
columns: Arc::clone(columns),
column_names: Arc::clone(column_names),
}
}
*/
}
impl Row for RqliteRow {
type Database = Rqlite;
fn columns(&self) -> &[RqliteColumn] {
&self.columns
}
fn try_get_raw<I>(&self, index: I) -> Result<RqliteValueRef<'_>, Error>
where
I: ColumnIndex<Self>,
{
let index = index.index(self)?;
Ok(RqliteValueRef::value(&self.values[index]))
}
}
impl ColumnIndex<RqliteRow> for &'_ str {
fn index(&self, row: &RqliteRow) -> Result<usize, Error> {
row.column_names
.get(*self)
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
.map(|v| *v)
}
}
// #[cfg(feature = "any")]
// impl From<RqliteRow> for crate::any::AnyRow {
// #[inline]
// fn from(row: RqliteRow) -> Self {
// crate::any::AnyRow {
// columns: row.columns.iter().map(|col| col.clone().into()).collect(),
// kind: crate::any::row::AnyRowKind::Rqlite(row),
// }
// }
// }