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
use crate::database::Database;
use either::Either;
use std::convert::identity;
#[derive(Debug)]
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "offline",
serde(bound(
serialize = "DB::TypeInfo: serde::Serialize, DB::Column: serde::Serialize",
deserialize = "DB::TypeInfo: serde::de::DeserializeOwned, DB::Column: serde::de::DeserializeOwned",
))
)]
#[doc(hidden)]
pub struct Describe<DB: Database> {
pub(crate) columns: Vec<DB::Column>,
pub(crate) parameters: Option<Either<Vec<DB::TypeInfo>, usize>>,
pub(crate) nullable: Vec<Option<bool>>,
}
impl<DB: Database> Describe<DB> {
pub fn columns(&self) -> &[DB::Column] {
&self.columns
}
pub fn column(&self, index: usize) -> &DB::Column {
&self.columns[index]
}
pub fn parameters(&self) -> Option<Either<&[DB::TypeInfo], usize>> {
self.parameters.as_ref().map(|p| match p {
Either::Left(params) => Either::Left(&**params),
Either::Right(count) => Either::Right(*count),
})
}
pub fn nullable(&self, column: usize) -> Option<bool> {
self.nullable.get(column).copied().and_then(identity)
}
}