| 1 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::databaserust-analyzer cargo sqlx-core 0.8.3 database/::Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#; |
| 2 | use eitherrust-analyzer cargo either 1.18.0 crate/::Eitherrust-analyzer cargo either 1.18.0 Either#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::identityrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/identity().; |
| 4 | |
| 5 | /// Provides extended information on a statement. |
| 6 | /// |
| 7 | /// Returned from [`Executor::describe`]. |
| 8 | /// |
| 9 | /// The query macros (e.g., `query!`, `query_as!`, etc.) use the information here to validate |
| 10 | /// output and parameter types; and, generate an anonymous record. |
| 11 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 12 | #[cfg_attr(feature = "offline", derive(serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_derive 1.0.229 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)] |
| 21 | pub struct Describerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> { |
| 22 | pub columnsrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#columns.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DB::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#>, |
| 23 | pub parametersrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#parameters.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Eitherrust-analyzer cargo either 1.18.0 Either#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DB::TypeInforust-analyzer cargo sqlx-core 0.8.3 database/Database#TypeInfo#>, usize>>, |
| 24 | pub nullablerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#nullable.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>>, |
| 25 | } |
| 26 | |
| 27 | impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Describerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#<DB> { |
| 28 | /// Gets all columns in this statement. |
| 29 | pub fn columnsrust-analyzer cargo sqlx-core 0.8.3 describe/impl#[`Describe<DB>`]columns().(&self) -> &[DB::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#] { |
| 30 | &self.columnsrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#columns. |
| 31 | } |
| 32 | |
| 33 | /// Gets the column information at `index`. |
| 34 | /// |
| 35 | /// Panics if `index` is out of bounds. |
| 36 | pub fn columnrust-analyzer cargo sqlx-core 0.8.3 describe/impl#[`Describe<DB>`]column().(&self, index: usize) -> &DB::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column# { |
| 37 | &self.columnsrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#columns.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 38 | } |
| 39 | |
| 40 | /// Gets the available information for parameters in this statement. |
| 41 | /// |
| 42 | /// Some drivers may return more or less than others. As an example, **PostgreSQL** will |
| 43 | /// return `Some(Either::Left(_))` with a full list of type information for each parameter. |
| 44 | /// However, **MSSQL** will return `None` as there is no information available. |
| 45 | pub fn parametersrust-analyzer cargo sqlx-core 0.8.3 describe/impl#[`Describe<DB>`]parameters().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Eitherrust-analyzer cargo either 1.18.0 Either#<&[DB::TypeInforust-analyzer cargo sqlx-core 0.8.3 database/Database#TypeInfo#], usize>> { |
| 46 | self.parametersrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#parameters..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| match p { |
| 47 | Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(params) => Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().params), |
| 48 | Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(count) => Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().count), |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | /// Gets whether a column may be `NULL`, if this information is available. |
| 53 | pub fn nullablerust-analyzer cargo sqlx-core 0.8.3 describe/impl#[`Describe<DB>`]nullable().(&self, column: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool> { |
| 54 | self.nullablerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#nullable..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(column).copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(identityrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/identity().) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | #[cfg(feature = "any")] |
| 59 | impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Describerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#<DB> { |
| 60 | #[doc(hidden)] |
| 61 | pub fn try_into_anyrust-analyzer cargo sqlx-core 0.8.3 describe/impl#[`Describe<DB>`]try_into_any().(self) -> craterust-analyzer cargo sqlx-core 0.8.3 crate/::Resultrust-analyzer cargo sqlx-core 0.8.3 error/Result#<Describerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#<craterust-analyzer cargo sqlx-core 0.8.3 crate/::anyrust-analyzer cargo sqlx-core 0.8.3 any/::Anyrust-analyzer cargo sqlx-core 0.8.3 any/database/Any#>> |
| 62 | where |
| 63 | craterust-analyzer cargo sqlx-core 0.8.3 crate/::anyrust-analyzer cargo sqlx-core 0.8.3 any/::AnyColumnrust-analyzer cargo sqlx-core 0.8.3 any/column/AnyColumn#: for<'a> TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&'a DB::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#, Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error# = craterust-analyzer cargo sqlx-core 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>, |
| 64 | craterust-analyzer cargo sqlx-core 0.8.3 crate/::anyrust-analyzer cargo sqlx-core 0.8.3 any/::AnyTypeInforust-analyzer cargo sqlx-core 0.8.3 any/type_info/AnyTypeInfo#: for<'a> TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&'a DB::TypeInforust-analyzer cargo sqlx-core 0.8.3 database/Database#TypeInfo#, Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error# = craterust-analyzer cargo sqlx-core 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>, |
| 65 | { |
| 66 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::anyrust-analyzer cargo sqlx-core 0.8.3 any/::AnyTypeInforust-analyzer cargo sqlx-core 0.8.3 any/type_info/AnyTypeInfo#; |
| 67 | |
| 68 | let columns = self |
| 69 | .columnsrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#columns. |
| 70 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 71 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(craterust-analyzer cargo sqlx-core 0.8.3 crate/::anyrust-analyzer cargo sqlx-core 0.8.3 any/::AnyColumnrust-analyzer cargo sqlx-core 0.8.3 any/column/AnyColumn#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#try_from().) |
| 72 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 73 | |
| 74 | let parameters = match self.parametersrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#parameters. { |
| 75 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(parameters)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#( |
| 76 | parameters |
| 77 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 78 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 79 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, type_info)| { |
| 80 | AnyTypeInforust-analyzer cargo sqlx-core 0.8.3 any/type_info/AnyTypeInfo#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#try_from().(type_info).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 81 | craterust-analyzer cargo sqlx-core 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::AnyDriverErrorrust-analyzer cargo sqlx-core 0.8.3 error/Error#AnyDriverError#( |
| 82 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 83 | "Any driver does not support type {type_info} of parameter {i}" |
| 84 | ) |
| 85 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 86 | ) |
| 87 | }) |
| 88 | }) |
| 89 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 90 | )), |
| 91 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(count)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(count)), |
| 92 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 93 | }; |
| 94 | |
| 95 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Describerust-analyzer cargo sqlx-core 0.8.3 describe/Describe# { |
| 96 | columnsrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#columns., |
| 97 | parametersrust-analyzer cargo sqlx-core 0.8.3 describe/Describe#parameters., |
| 98 | nullablerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#nullable.: self.nullablerust-analyzer cargo sqlx-core 0.8.3 describe/Describe#nullable., |
| 99 | }) |
| 100 | } |
| 101 | } |