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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use std::future::Future;

use crate::{C3p0Error, DataType, IdType, JsonCodec, Model, NewModel};

pub mod codec;
pub mod model;
pub mod types;

pub trait C3p0Json<Id, Data, Codec>: Clone + Send + Sync
where
    Id: IdType,
    Data: DataType,
    Codec: JsonCodec<Data>,
{
    type Tx;

    fn codec(&self) -> &Codec;

    fn create_table_if_not_exists(
        &self,
        tx: &mut Self::Tx,
    ) -> impl Future<Output = Result<(), C3p0Error>> + Send;

    fn drop_table_if_exists(
        &self,
        tx: &mut Self::Tx,
        cascade: bool,
    ) -> impl Future<Output = Result<(), C3p0Error>> + Send;

    fn count_all(&self, tx: &mut Self::Tx) -> impl Future<Output = Result<u64, C3p0Error>> + Send;

    fn exists_by_id(
        &self,
        tx: &mut Self::Tx,
        id: &Id,
    ) -> impl Future<Output = Result<bool, C3p0Error>> + Send;

    fn fetch_all(
        &self,
        tx: &mut Self::Tx,
    ) -> impl Future<Output = Result<Vec<Model<Id, Data>>, C3p0Error>> + Send;

    fn fetch_one_optional_by_id(
        &self,
        tx: &mut Self::Tx,
        id: &Id,
    ) -> impl Future<Output = Result<Option<Model<Id, Data>>, C3p0Error>> + Send;

    fn fetch_one_by_id(
        &self,
        tx: &mut Self::Tx,
        id: &Id,
    ) -> impl Future<Output = Result<Model<Id, Data>, C3p0Error>> + Send;

    fn delete(
        &self,
        tx: &mut Self::Tx,
        obj: Model<Id, Data>,
    ) -> impl Future<Output = Result<Model<Id, Data>, C3p0Error>> + Send;

    fn delete_all(&self, tx: &mut Self::Tx) -> impl Future<Output = Result<u64, C3p0Error>> + Send;

    fn delete_by_id(
        &self,
        tx: &mut Self::Tx,
        id: &Id,
    ) -> impl Future<Output = Result<u64, C3p0Error>> + Send;

    fn save(
        &self,
        tx: &mut Self::Tx,
        obj: NewModel<Data>,
    ) -> impl Future<Output = Result<Model<Id, Data>, C3p0Error>> + Send;

    fn update(
        &self,
        tx: &mut Self::Tx,
        obj: Model<Id, Data>,
    ) -> impl Future<Output = Result<Model<Id, Data>, C3p0Error>> + Send;
}

#[derive(Clone)]
pub struct Queries {
    pub id_field_name: String,
    pub version_field_name: String,
    pub create_epoch_millis_field_name: String,
    pub update_epoch_millis_field_name: String,
    pub data_field_name: String,

    pub table_name: String,
    pub schema_name: Option<String>,
    pub qualified_table_name: String,

    pub count_all_sql_query: String,
    pub exists_by_id_sql_query: String,

    pub find_base_sql_query: String,
    pub find_all_sql_query: String,
    pub find_by_id_sql_query: String,

    pub delete_sql_query: String,
    pub delete_all_sql_query: String,
    pub delete_by_id_sql_query: String,

    pub save_sql_query: String,
    pub save_sql_query_with_id: String,

    pub update_sql_query: String,

    pub create_table_sql_query: String,
    pub drop_table_sql_query: String,
    pub drop_table_sql_query_cascade: String,
    pub lock_table_sql_query: Option<String>,
}