Debian Codegraph @

src/row.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::columnrust-analyzer cargo sqlx-core 0.8.3 column/::ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#;
2 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#;
3 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#;
4 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::{mismatched_typesrust-analyzer cargo sqlx-core 0.8.3 error/mismatched_types()., Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#};
5
6 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::type_inforust-analyzer cargo sqlx-core 0.8.3 type_info/::TypeInforust-analyzer cargo sqlx-core 0.8.3 type_info/TypeInfo#;
7 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::typesrust-analyzer cargo sqlx-core 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#;
8 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::valuerust-analyzer cargo sqlx-core 0.8.3 value/::ValueRefrust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#;
9
10 /// Represents a single row from the database.
11 ///
12 /// [`FromRow`]: crate::row::FromRow
13 /// [`Query::fetch`]: crate::query::Query::fetch
14 pub trait Rowrust-analyzer cargo sqlx-core 0.8.3 row/Row#: Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static {
15 type Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#<Rowrust-analyzer cargo sqlx-core 0.8.3 database/Database#Row# = Self>;
16
17 /// Returns `true` if this row has no columns.
18 #[inline]
19 fn is_emptyrust-analyzer cargo sqlx-core 0.8.3 row/Row#is_empty().(&self) -> bool {
20 self.lenrust-analyzer cargo sqlx-core 0.8.3 row/Row#len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0
21 }
22
23 /// Returns the number of columns in this row.
24 #[inline]
25 fn lenrust-analyzer cargo sqlx-core 0.8.3 row/Row#len().(&self) -> usize {
26 self.columnsrust-analyzer cargo sqlx-core 0.8.3 row/Row#columns().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()
27 }
28
29 /// Gets the column information at `index`.
30 ///
31 /// A string index can be used to access a column by name and a `usize` index
32 /// can be used to access a column by position.
33 ///
34 /// # Panics
35 ///
36 /// Panics if `index` is out of bounds.
37 /// See [`try_column`](Self::try_column) for a non-panicking version.
38 fn columnrust-analyzer cargo sqlx-core 0.8.3 row/Row#column().<I>(&self, index: I) -> &<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#
39 where
40 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
41 {
42 self.try_columnrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_column().(index).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
43 }
44
45 /// Gets the column information at `index` or a `ColumnIndexOutOfBounds` error if out of bounds.
46 fn try_columnrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_column().<I>(&self, index: I) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
47 where
48 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
49 {
50 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.columnsrust-analyzer cargo sqlx-core 0.8.3 row/Row#columns().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().index.indexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#index().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)
51 }
52
53 /// Gets all columns in this statement.
54 fn columnsrust-analyzer cargo sqlx-core 0.8.3 row/Row#columns().(&self) -> &[<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column#];
55
56 /// Index into the database row and decode a single value.
57 ///
58 /// A string index can be used to access a column by name and a `usize` index
59 /// can be used to access a column by position.
60 ///
61 /// # Panics
62 ///
63 /// Panics if the column does not exist or its value cannot be decoded into the requested type.
64 /// See [`try_get`](Self::try_get) for a non-panicking version.
65 ///
66 #[inline]
67 fn getrust-analyzer cargo sqlx-core 0.8.3 row/Row#get().<'r, T, I>(&'r self, index: I) -> T
68 where
69 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
70 T: Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#> + Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#>,
71 {
72 self.try_getrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get().::<T, I>(index).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
73 }
74
75 /// Index into the database row and decode a single value.
76 ///
77 /// Unlike [`get`](Self::get), this method does not check that the type
78 /// being returned from the database is compatible with the Rust type and blindly tries
79 /// to decode the value.
80 ///
81 /// # Panics
82 ///
83 /// Panics if the column does not exist or its value cannot be decoded into the requested type.
84 /// See [`try_get_unchecked`](Self::try_get_unchecked) for a non-panicking version.
85 ///
86 #[inline]
87 fn get_uncheckedrust-analyzer cargo sqlx-core 0.8.3 row/Row#get_unchecked().<'r, T, I>(&'r self, index: I) -> T
88 where
89 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
90 T: Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#>,
91 {
92 self.try_get_uncheckedrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get_unchecked().::<T, I>(index).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
93 }
94
95 /// Index into the database row and decode a single value.
96 ///
97 /// A string index can be used to access a column by name and a `usize` index
98 /// can be used to access a column by position.
99 ///
100 /// # Errors
101 ///
102 /// * [`ColumnNotFound`] if the column by the given name was not found.
103 /// * [`ColumnIndexOutOfBounds`] if the `usize` index was greater than the number of columns in the row.
104 /// * [`ColumnDecode`] if the value could not be decoded into the requested type.
105 ///
106 /// [`ColumnDecode`]: Error::ColumnDecode
107 /// [`ColumnNotFound`]: Error::ColumnNotFound
108 /// [`ColumnIndexOutOfBounds`]: Error::ColumnIndexOutOfBounds
109 ///
110 fn try_getrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get().<'r, T, I>(&'r self, index: I) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
111 where
112 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
113 T: Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#> + Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#>,
114 {
115 let value = self.try_get_rawrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get_raw().(&index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
116
117 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.is_nullrust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#is_null().() {
118 let ty = value.type_inforust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#type_info().();
119
120 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ty.is_nullrust-analyzer cargo sqlx-core 0.8.3 type_info/TypeInfo#is_null().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().T::compatiblerust-analyzer cargo sqlx-core 0.8.3 types/Type#compatible().(&ty) {
121 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::ColumnDecoderust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode# {
122 indexrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#index.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{index:?}"),
123 sourcerust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#source.: mismatched_typesrust-analyzer cargo sqlx-core 0.8.3 error/mismatched_types().::<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#, T>(&ty),
124 });
125 }
126 }
127
128 T::decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#decode().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|source| Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::ColumnDecoderust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode# {
129 indexrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#index.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{index:?}"),
130 sourcerust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#source.,
131 })
132 }
133
134 /// Index into the database row and decode a single value.
135 ///
136 /// Unlike [`try_get`](Self::try_get), this method does not check that the type
137 /// being returned from the database is compatible with the Rust type and blindly tries
138 /// to decode the value.
139 ///
140 /// # Errors
141 ///
142 /// * [`ColumnNotFound`] if the column by the given name was not found.
143 /// * [`ColumnIndexOutOfBounds`] if the `usize` index was greater than the number of columns in the row.
144 /// * [`ColumnDecode`] if the value could not be decoded into the requested type.
145 ///
146 /// [`ColumnDecode`]: Error::ColumnDecode
147 /// [`ColumnNotFound`]: Error::ColumnNotFound
148 /// [`ColumnIndexOutOfBounds`]: Error::ColumnIndexOutOfBounds
149 ///
150 #[inline]
151 fn try_get_uncheckedrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get_unchecked().<'r, T, I>(&'r self, index: I) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
152 where
153 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>,
154 T: Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database#>,
155 {
156 let value = self.try_get_rawrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get_raw().(&index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
157
158 T::decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#decode().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|source| Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::ColumnDecoderust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode# {
159 indexrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#index.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{index:?}"),
160 sourcerust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#source.,
161 })
162 }
163
164 /// Index into the database row and decode a single value.
165 ///
166 /// # Errors
167 ///
168 /// * [`ColumnNotFound`] if the column by the given name was not found.
169 /// * [`ColumnIndexOutOfBounds`] if the `usize` index was greater than the number of columns in the row.
170 ///
171 /// [`ColumnNotFound`]: Error::ColumnNotFound
172 /// [`ColumnIndexOutOfBounds`]: Error::ColumnIndexOutOfBounds
173 ///
174 fn try_get_rawrust-analyzer cargo sqlx-core 0.8.3 row/Row#try_get_raw().<I>(&self, index: I) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 row/Row#Database# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::ValueRefrust-analyzer cargo sqlx-core 0.8.3 database/Database#ValueRef#<'_>, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
175 where
176 I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<Self>;
177 }