bmbp_rdbc_sql 0.2.8

SQL构建器
Documentation
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
use bmbp_rdbc_sql::{PgRdbcSQLBuilder, QueryWrapper, RdbcTableFilter, SQLBuilder};
use bmbp_rdbc_sql::{QueryFilter, RdbcTableWrapper};
use bmbp_rdbc_type::{RdbcIdent, RdbcTable};
use serde::Deserialize;
use serde::Serialize;
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct BmbpDict {
    dict_value: Option<String>,
    dict_alias: Option<String>,
    data_id: Option<String>,
    data_level: Option<String>,
    data_flag: Option<String>,
    data_status: Option<String>,
    data_sort: Option<i32>,
    data_create_time: Option<String>,
    data_create_user: Option<String>,
    data_update_time: Option<String>,
    data_update_user: Option<String>,
    data_owner_org: Option<String>,
    data_sign: Option<String>,
    dict_code: Option<String>,
    dict_parent_code: Option<String>,
    dict_name: Option<String>,
    dict_code_path: Option<String>,
    dict_name_path: Option<String>,
    dict_tree_grade: Option<u32>,
    dict_leaf: Option<String>,
    dict_type: Option<String>,
    dict_children: Option<Vec<BmbpDict>>,
}
impl BmbpDict {
    pub fn new() -> Self {
        Self::default()
    }
    pub fn set_dict_value(&mut self, value: Option<String>) -> &mut Self {
        self.dict_value = value;
        self
    }
    pub fn get_dict_value(&self) -> &Option<String> {
        &self.dict_value
    }
    pub fn get_mut_dict_value(&mut self) -> &mut Option<String> {
        &mut self.dict_value
    }
    pub fn set_dict_alias(&mut self, value: Option<String>) -> &mut Self {
        self.dict_alias = value;
        self
    }
    pub fn get_dict_alias(&self) -> &Option<String> {
        &self.dict_alias
    }
    pub fn get_mut_dict_alias(&mut self) -> &mut Option<String> {
        &mut self.dict_alias
    }
    pub fn set_data_id(&mut self, value: Option<String>) -> &mut Self {
        self.data_id = value;
        self
    }
    pub fn get_data_id(&self) -> &Option<String> {
        &self.data_id
    }
    pub fn get_mut_data_id(&mut self) -> &mut Option<String> {
        &mut self.data_id
    }
    pub fn set_data_level(&mut self, value: Option<String>) -> &mut Self {
        self.data_level = value;
        self
    }
    pub fn get_data_level(&self) -> &Option<String> {
        &self.data_level
    }
    pub fn get_mut_data_level(&mut self) -> &mut Option<String> {
        &mut self.data_level
    }
    pub fn set_data_flag(&mut self, value: Option<String>) -> &mut Self {
        self.data_flag = value;
        self
    }
    pub fn get_data_flag(&self) -> &Option<String> {
        &self.data_flag
    }
    pub fn get_mut_data_flag(&mut self) -> &mut Option<String> {
        &mut self.data_flag
    }
    pub fn set_data_status(&mut self, value: Option<String>) -> &mut Self {
        self.data_status = value;
        self
    }
    pub fn get_data_status(&self) -> &Option<String> {
        &self.data_status
    }
    pub fn get_mut_data_status(&mut self) -> &mut Option<String> {
        &mut self.data_status
    }
    pub fn set_data_sort(&mut self, value: Option<i32>) -> &mut Self {
        self.data_sort = value;
        self
    }
    pub fn get_data_sort(&self) -> &Option<i32> {
        &self.data_sort
    }
    pub fn get_mut_data_sort(&mut self) -> &mut Option<i32> {
        &mut self.data_sort
    }
    pub fn set_data_create_time(&mut self, value: Option<String>) -> &mut Self {
        self.data_create_time = value;
        self
    }
    pub fn get_data_create_time(&self) -> &Option<String> {
        &self.data_create_time
    }
    pub fn get_mut_data_create_time(&mut self) -> &mut Option<String> {
        &mut self.data_create_time
    }
    pub fn set_data_create_user(&mut self, value: Option<String>) -> &mut Self {
        self.data_create_user = value;
        self
    }
    pub fn get_data_create_user(&self) -> &Option<String> {
        &self.data_create_user
    }
    pub fn get_mut_data_create_user(&mut self) -> &mut Option<String> {
        &mut self.data_create_user
    }
    pub fn set_data_update_time(&mut self, value: Option<String>) -> &mut Self {
        self.data_update_time = value;
        self
    }
    pub fn get_data_update_time(&self) -> &Option<String> {
        &self.data_update_time
    }
    pub fn get_mut_data_update_time(&mut self) -> &mut Option<String> {
        &mut self.data_update_time
    }
    pub fn set_data_update_user(&mut self, value: Option<String>) -> &mut Self {
        self.data_update_user = value;
        self
    }
    pub fn get_data_update_user(&self) -> &Option<String> {
        &self.data_update_user
    }
    pub fn get_mut_data_update_user(&mut self) -> &mut Option<String> {
        &mut self.data_update_user
    }
    pub fn set_data_owner_org(&mut self, value: Option<String>) -> &mut Self {
        self.data_owner_org = value;
        self
    }
    pub fn get_data_owner_org(&self) -> &Option<String> {
        &self.data_owner_org
    }
    pub fn get_mut_data_owner_org(&mut self) -> &mut Option<String> {
        &mut self.data_owner_org
    }
    pub fn set_data_sign(&mut self, value: Option<String>) -> &mut Self {
        self.data_sign = value;
        self
    }
    pub fn get_data_sign(&self) -> &Option<String> {
        &self.data_sign
    }
    pub fn get_mut_data_sign(&mut self) -> &mut Option<String> {
        &mut self.data_sign
    }
    pub fn set_dict_code(&mut self, value: Option<String>) -> &mut Self {
        self.dict_code = value;
        self
    }
    pub fn get_dict_code(&self) -> &Option<String> {
        &self.dict_code
    }
    pub fn get_mut_dict_code(&mut self) -> &mut Option<String> {
        &mut self.dict_code
    }
    pub fn set_dict_parent_code(&mut self, value: Option<String>) -> &mut Self {
        self.dict_parent_code = value;
        self
    }
    pub fn get_dict_parent_code(&self) -> &Option<String> {
        &self.dict_parent_code
    }
    pub fn get_mut_dict_parent_code(&mut self) -> &mut Option<String> {
        &mut self.dict_parent_code
    }
    pub fn set_dict_name(&mut self, value: Option<String>) -> &mut Self {
        self.dict_name = value;
        self
    }
    pub fn get_dict_name(&self) -> &Option<String> {
        &self.dict_name
    }
    pub fn get_mut_dict_name(&mut self) -> &mut Option<String> {
        &mut self.dict_name
    }
    pub fn set_dict_code_path(&mut self, value: Option<String>) -> &mut Self {
        self.dict_code_path = value;
        self
    }
    pub fn get_dict_code_path(&self) -> &Option<String> {
        &self.dict_code_path
    }
    pub fn get_mut_dict_code_path(&mut self) -> &mut Option<String> {
        &mut self.dict_code_path
    }
    pub fn set_dict_name_path(&mut self, value: Option<String>) -> &mut Self {
        self.dict_name_path = value;
        self
    }
    pub fn get_dict_name_path(&self) -> &Option<String> {
        &self.dict_name_path
    }
    pub fn get_mut_dict_name_path(&mut self) -> &mut Option<String> {
        &mut self.dict_name_path
    }
    pub fn set_dict_tree_grade(&mut self, value: Option<u32>) -> &mut Self {
        self.dict_tree_grade = value;
        self
    }
    pub fn get_dict_tree_grade(&self) -> &Option<u32> {
        &self.dict_tree_grade
    }
    pub fn get_mut_dict_tree_grade(&mut self) -> &mut Option<u32> {
        &mut self.dict_tree_grade
    }
    pub fn set_dict_leaf(&mut self, value: Option<String>) -> &mut Self {
        self.dict_leaf = value;
        self
    }
    pub fn get_dict_leaf(&self) -> &Option<String> {
        &self.dict_leaf
    }
    pub fn get_mut_dict_leaf(&mut self) -> &mut Option<String> {
        &mut self.dict_leaf
    }
    pub fn set_dict_type(&mut self, value: Option<String>) -> &mut Self {
        self.dict_type = value;
        self
    }
    pub fn get_dict_type(&self) -> &Option<String> {
        &self.dict_type
    }
    pub fn get_mut_dict_type(&mut self) -> &mut Option<String> {
        &mut self.dict_type
    }
    pub fn set_dict_children(&mut self, value: Option<Vec<BmbpDict>>) -> &mut Self {
        self.dict_children = value;
        self
    }
    pub fn get_dict_children(&self) -> &Option<Vec<BmbpDict>> {
        &self.dict_children
    }
    pub fn get_mut_dict_children(&mut self) -> &mut Option<Vec<BmbpDict>> {
        &mut self.dict_children
    }
}
pub enum BmbpDictColumn {
    DictValue,
    DictAlias,
    DataId,
    DataLevel,
    DataFlag,
    DataStatus,
    DataSort,
    DataCreateTime,
    DataCreateUser,
    DataUpdateTime,
    DataUpdateUser,
    DataOwnerOrg,
    DataSign,
    DictCode,
    DictParentCode,
    DictName,
    DictCodePath,
    DictNamePath,
    DictTreeGrade,
    DictLeaf,
    DictType,
}
impl RdbcIdent for BmbpDictColumn {
    fn get_ident(&self) -> String {
        match self {
            Self::DictValue => "dict_value".to_string(),
            Self::DictAlias => "dict_alias".to_string(),
            Self::DataId => "data_id".to_string(),
            Self::DataLevel => "data_level".to_string(),
            Self::DataFlag => "data_flag".to_string(),
            Self::DataStatus => "data_status".to_string(),
            Self::DataSort => "data_sort".to_string(),
            Self::DataCreateTime => "data_create_time".to_string(),
            Self::DataCreateUser => "data_create_user".to_string(),
            Self::DataUpdateTime => "data_update_time".to_string(),
            Self::DataUpdateUser => "data_update_user".to_string(),
            Self::DataOwnerOrg => "data_owner_org".to_string(),
            Self::DataSign => "data_sign".to_string(),
            Self::DictCode => "dict_code".to_string(),
            Self::DictParentCode => "dict_parent_code".to_string(),
            Self::DictName => "dict_name".to_string(),
            Self::DictCodePath => "dict_code_path".to_string(),
            Self::DictNamePath => "dict_name_path".to_string(),
            Self::DictTreeGrade => "dict_tree_grade".to_string(),
            Self::DictLeaf => "dict_leaf".to_string(),
            Self::DictType => "dict_type".to_string(),
        }
    }
}
impl RdbcTable for BmbpDict {
    fn get_table() -> impl RdbcIdent {
        "BMBP_CONFIG_DICT".to_string()
    }
    fn get_columns() -> Vec<impl RdbcIdent> {
        vec![
            BmbpDictColumn::DictValue,
            BmbpDictColumn::DictAlias,
            BmbpDictColumn::DataId,
            BmbpDictColumn::DataLevel,
            BmbpDictColumn::DataFlag,
            BmbpDictColumn::DataStatus,
            BmbpDictColumn::DataSort,
            BmbpDictColumn::DataCreateTime,
            BmbpDictColumn::DataCreateUser,
            BmbpDictColumn::DataUpdateTime,
            BmbpDictColumn::DataUpdateUser,
            BmbpDictColumn::DataOwnerOrg,
            BmbpDictColumn::DataSign,
            BmbpDictColumn::DictCode,
            BmbpDictColumn::DictParentCode,
            BmbpDictColumn::DictName,
            BmbpDictColumn::DictCodePath,
            BmbpDictColumn::DictNamePath,
            BmbpDictColumn::DictTreeGrade,
            BmbpDictColumn::DictLeaf,
            BmbpDictColumn::DictType,
        ]
    }
    fn get_primary_key() -> impl RdbcIdent {
        "data_id".to_string()
    }
    fn get_union_key() -> Vec<impl RdbcIdent> {
        vec!["data_id".to_string()]
    }
}
#[test]
fn test_query_new_from() {
    let query_wrapper = QueryWrapper::new_from::<BmbpDict>();
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>{}", sql);
}
#[test]
fn test_query_select_default() {
    let mut query_wrapper = QueryWrapper::new();
    query_wrapper.table(BmbpDict::get_table());
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}
#[test]
fn test_query_select() {
    let mut query_wrapper = QueryWrapper::new();
    query_wrapper.table(BmbpDict::get_table());
    query_wrapper.select_value("1");
    query_wrapper.select_value_alias(1, "demo");
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}

#[test]
fn test_query_select_filter() {
    let mut query_wrapper = QueryWrapper::new_from::<BmbpDict>();
    query_wrapper.in_v(BmbpDictColumn::DictCode, vec!["D", "D", "C"]);
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}

#[test]
fn test_query_select_table() {
    let mut query_wrapper = QueryWrapper::new_from::<BmbpDict>();
    query_wrapper
        .table(BmbpDict::get_table())
        .table("A1")
        .table_alias(BmbpDict::get_table(), "t1");
    query_wrapper.schema_table("bmbp", BmbpDict::get_table());
    query_wrapper.schema_table_alias("bmbp", BmbpDict::get_table(), "t3");
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}

#[test]
fn test_query_select_join_table() {
    let mut query_wrapper = QueryWrapper::new_from::<BmbpDict>();
    query_wrapper
        .table(BmbpDict::get_table())
        .table("A1")
        .table_alias(BmbpDict::get_table(), "t1");
    query_wrapper.schema_table("bmbp", BmbpDict::get_table());
    query_wrapper.schema_table_alias("bmbp", BmbpDict::get_table(), "t3");
    query_wrapper.join_table(BmbpDict::get_table());
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}
#[test]
fn test_query_select_left_table() {
    let mut query_wrapper = QueryWrapper::new_from::<BmbpDict>();
    query_wrapper
        .table(BmbpDict::get_table())
        .table("A1")
        .table_alias(BmbpDict::get_table(), "t1");
    query_wrapper.schema_table("bmbp", BmbpDict::get_table());
    query_wrapper.schema_table_alias("bmbp", BmbpDict::get_table(), "t3");
    let mut filter = QueryFilter::new();
    filter.eq_column("t1.name", "t2.name");
    query_wrapper
        .left_join_table(BmbpDict::get_table())
        .on()
        .eq_column("t1.name", "t2.name");
    let (sql, _) = SQLBuilder::build_query_script::<PgRdbcSQLBuilder>(&query_wrapper);
    println!("===>: {}", sql);
}