sqlx_core_oldapi/
describe.rs1use crate::database::Database;
2use either::Either;
3use std::convert::identity;
4
5#[derive(Debug)]
12#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
13#[cfg_attr(
14 feature = "offline",
15 serde(bound(
16 serialize = "DB::TypeInfo: serde::Serialize, DB::Column: serde::Serialize",
17 deserialize = "DB::TypeInfo: serde::de::DeserializeOwned, DB::Column: serde::de::DeserializeOwned",
18 ))
19)]
20#[doc(hidden)]
21pub struct Describe<DB: Database> {
22 pub(crate) columns: Vec<DB::Column>,
23 pub(crate) parameters: Option<Either<Vec<DB::TypeInfo>, usize>>,
24 pub(crate) nullable: Vec<Option<bool>>,
25}
26
27impl<DB: Database> Describe<DB> {
28 pub fn columns(&self) -> &[DB::Column] {
30 &self.columns
31 }
32
33 pub fn column(&self, index: usize) -> &DB::Column {
37 &self.columns[index]
38 }
39
40 pub fn parameters(&self) -> Option<Either<&[DB::TypeInfo], usize>> {
46 self.parameters.as_ref().map(|p| match p {
47 Either::Left(params) => Either::Left(&**params),
48 Either::Right(count) => Either::Right(*count),
49 })
50 }
51
52 pub fn nullable(&self, column: usize) -> Option<bool> {
54 self.nullable.get(column).copied().and_then(identity)
55 }
56}