ydb_unofficial/sqlx/
statement.rs

1use sqlx_core::{statement::Statement, Either};
2use ydb_grpc_bindings::generated::ydb;
3
4use super::prelude::*;
5
6const NO_COLUMNS: &[YdbColumn] = &[];
7
8#[derive(Debug, Clone)]
9pub(crate) struct NamedParameters {
10    names: Vec<String>,
11    types: Vec<YdbTypeInfo>,
12}
13
14impl From<std::collections::HashMap<String, ydb::Type>> for NamedParameters {
15    fn from(value: std::collections::HashMap<String, ydb::Type>) -> Self {
16        let cap = value.len();
17        let (names,types) = value.into_iter()
18        .filter_map(|(k,ty)|{Some((k, YdbTypeInfo::from(&ty.r#type?)))})
19        .fold((Vec::with_capacity(cap), Vec::with_capacity(cap)), |(mut names, mut types), (n,t)|{
20            names.push(n);
21            types.push(t);
22            (names, types)
23        });
24        Self{names, types}
25    }
26}
27
28#[derive(Debug, Clone)]
29pub struct YdbStatement {
30    pub (crate) query_id: String,
31    pub (crate) yql: String,
32    pub (crate) parameters: NamedParameters,
33}
34
35impl YdbStatement {
36    pub fn query_id(&self) -> &str {
37        &self.query_id
38    }
39}
40
41impl Statement<'_> for YdbStatement {
42    type Database = Ydb;
43
44    fn to_owned(&self) -> YdbStatement {
45        self.clone()
46    }
47
48    fn sql(&self) -> &str {
49        &self.yql
50    }
51
52    fn parameters(&self) -> Option<Either<&[YdbTypeInfo], usize>> {
53        Some(Either::Left(&self.parameters.types))
54    }
55
56    fn columns(&self) -> &[YdbColumn] {
57        //TODO: определиться, зачем тут колонки
58        NO_COLUMNS
59    }
60
61    sqlx_core::impl_statement_query!(YdbArguments);
62}