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
use sqlx_core::arguments::IntoArguments;
use sqlx_core::arguments::Arguments;
use sqlx_core::database::{Database, HasArguments, HasStatement, HasValueRef};
use ydb_grpc_bindings::generated::ydb;

use super::prelude::*;

pub type YdbArgumentBuffer = std::collections::HashMap<String, ydb::TypedValue>;

#[derive(Debug, Clone, Copy, Default)]
pub struct Ydb;

impl Database for Ydb {
    type Connection = YdbConnection;

    type TransactionManager = YdbTransactionManager;

    type Row = YdbRow;

    type QueryResult = YdbQueryResult;

    type Column = YdbColumn;

    type TypeInfo = YdbTypeInfo;

    type Value = YdbValue;

    const NAME: &'static str = "Ydb";

    const URL_SCHEMES: &'static [&'static str] = &["ydb", "ydbs"];
}

impl<'a> HasArguments<'a> for Ydb {
    type Database = Self;

    type Arguments = YdbArguments;

    type ArgumentBuffer=YdbArgumentBuffer;
}

#[derive(Debug, Default, Clone)]
pub struct YdbArguments(pub(crate) YdbArgumentBuffer);

impl<'q> Arguments<'q> for YdbArguments {
    type Database = Ydb;

    fn reserve(&mut self, _additional: usize, _size: usize) {
        //TODO: implement me
    }

    fn add<T>(&mut self, value: T)
    where T: 'q + Send + sqlx_core::encode::Encode<'q, Ydb> + sqlx_core::types::Type<Ydb> {
        let _ = value.encode(&mut self.0);
    }
}

impl<'a> IntoArguments<'a, Ydb> for &YdbArguments {
    fn into_arguments(self) -> YdbArguments {
        self.clone()
    }
}

impl IntoArguments<'_, Ydb> for YdbArguments {
    fn into_arguments(self) -> YdbArguments {
        self
    }
}

impl <'a> HasStatement<'a> for Ydb {
    type Database = Self;

    type Statement = YdbStatement;
}

impl <'a> HasValueRef<'a> for Ydb {
    type Database = Self;
    type ValueRef = YdbValueRef<'a>;
}