forked from diesel-rs/diesel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_structures.rs
More file actions
59 lines (51 loc) · 1.56 KB
/
Copy pathdata_structures.rs
File metadata and controls
59 lines (51 loc) · 1.56 KB
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
use diesel::*;
#[cfg(feature="uses_information_schema")]
use diesel::backend::Backend;
#[cfg(feature = "sqlite")]
use diesel::sqlite::Sqlite;
use diesel::types::{HasSqlType, FromSqlRow};
#[cfg(feature="uses_information_schema")]
use super::information_schema::UsesInformationSchema;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnInformation {
pub column_name: String,
pub type_name: String,
pub nullable: bool,
}
pub struct ColumnType {
pub path: Vec<String>,
pub is_array: bool,
pub is_nullable: bool,
}
impl ColumnInformation {
pub fn new<T, U>(column_name: T, type_name: U, nullable: bool) -> Self where
T: Into<String>,
U: Into<String>,
{
ColumnInformation {
column_name: column_name.into(),
type_name: type_name.into(),
nullable: nullable,
}
}
}
#[cfg(feature="uses_information_schema")]
impl<ST, DB> Queryable<ST, DB> for ColumnInformation where
DB: Backend + UsesInformationSchema + HasSqlType<ST>,
(String, String, String): FromSqlRow<ST, DB>,
{
type Row = (String, String, String);
fn build(row: Self::Row) -> Self {
ColumnInformation::new(row.0, row.1, row.2 == "YES")
}
}
#[cfg(feature = "sqlite")]
impl<ST> Queryable<ST, Sqlite> for ColumnInformation where
Sqlite: HasSqlType<ST>,
(i32, String, String, bool, Option<String>, bool): FromSqlRow<ST, Sqlite>,
{
type Row = (i32, String, String, bool, Option<String>, bool);
fn build(row: Self::Row) -> Self {
ColumnInformation::new(row.1, row.2, !row.3)
}
}