@@ -15,8 +15,6 @@ use tokio_postgres::{self};
1515use crate :: mapper:: RowMapper ;
1616use crate :: row:: Row ;
1717
18- use cfg_if:: cfg_if;
19-
2018/// Lightweight wrapper over the collection of results of the different crates
2119/// supported by Canyon-SQL.
2220///
@@ -33,16 +31,6 @@ pub enum CanyonRows {
3331 MySQL ( Vec < mysql_async:: Row > ) ,
3432}
3533
36- // impl IntoResults for Result<CanyonRows, CanyonError> {
37- // fn into_results<R>(self) -> Result<Vec<R>, CanyonError>
38- // where
39- // R: RowMapper,
40- // Vec<R>: FromIterator<<R as RowMapper>::Output>,
41- // {
42- // self.map(move |rows| rows.into_results::<R>())
43- // }
44- // }
45-
4634impl CanyonRows {
4735 #[ cfg( feature = "postgres" ) ]
4836 pub fn get_postgres_rows ( & self ) -> & Vec < tokio_postgres:: Row > {
@@ -68,22 +56,6 @@ impl CanyonRows {
6856 }
6957 }
7058
71- // /// Consumes `self` and returns the wrapped [`std::vec::Vec`] with the instances of R
72- // pub fn into_results<R>(self) -> Vec<R>
73- // where
74- // R: RowMapper,
75- // Vec<R>: FromIterator<<R as RowMapper>::Output>,
76- // {
77- // match self {
78- // #[cfg(feature = "postgres")]
79- // Self::Postgres(v) => v.iter().map(|row| R::deserialize_postgresql(row)?).collect(),
80- // #[cfg(feature = "mssql")]
81- // Self::Tiberius(v) => v.iter().map(|row| R::deserialize_sqlserver(row)?).collect(),
82- // #[cfg(feature = "mysql")]
83- // Self::MySQL(v) => v.iter().map(|row| R::deserialize_mysql(row)?).collect(),
84- // }
85- // }
86-
8759 /// Returns the entity at the given index for the returned rows
8860 ///
8961 /// This is just a wrapper get operation over the [Vec] get operation
@@ -136,90 +108,108 @@ impl CanyonRows {
136108 }
137109}
138110
139- cfg_if ! {
140- if #[ cfg( all( feature = "postgres" , feature = "mysql" , feature = "mssql" ) ) ] {
141- pub trait FromSql <' a, T >: tokio_postgres:: types:: FromSql <' a>
142- + tiberius:: FromSql <' a>
143- + mysql_async:: prelude:: FromValue { }
144- impl <' a, T > FromSql <' a, T > for T where T :
145- tokio_postgres:: types:: FromSql <' a>
146- + tiberius:: FromSql <' a>
147- + mysql_async:: prelude:: FromValue
148- { }
149-
150- pub trait FromSqlOwnedValue <T >: tokio_postgres:: types:: FromSqlOwned
151- + tiberius:: FromSqlOwned
152- + mysql_async:: prelude:: FromValue { }
153- impl <T > FromSqlOwnedValue <T > for T where T :
154- tokio_postgres:: types:: FromSqlOwned
155- + tiberius:: FromSqlOwned
156- + mysql_async:: prelude:: FromValue
157- { }
158- } else if #[ cfg( all( feature = "postgres" , feature = "mysql" ) ) ] {
159- pub trait FromSql <' a, T >: tokio_postgres:: types:: FromSql <' a>
160- + mysql_async:: prelude:: FromValue { }
161- impl <' a, T > FromSql <' a, T > for T where T :
162- tokio_postgres:: types:: FromSql <' a>
163- + mysql_async:: prelude:: FromValue
164- { }
165-
166- pub trait FromSqlOwnedValue <T >: tokio_postgres:: types:: FromSqlOwned
167- + mysql_async:: prelude:: FromValue { }
168- impl <T > FromSqlOwnedValue <T > for T where T :
169- tokio_postgres:: types:: FromSqlOwned
170- + mysql_async:: prelude:: FromValue
171- { }
172- } else if #[ cfg( all( feature = "postgres" , feature = "mssql" ) ) ] {
173- pub trait FromSql <' a, T >: tokio_postgres:: types:: FromSql <' a>
174- + tiberius:: FromSql <' a> { }
175- impl <' a, T > FromSql <' a, T > for T where T :
176- tokio_postgres:: types:: FromSql <' a>
177- + tiberius:: FromSql <' a>
178- { }
179-
180- pub trait FromSqlOwnedValue <T >: tokio_postgres:: types:: FromSqlOwned
181- + tiberius:: FromSqlOwned { }
182- impl <T > FromSqlOwnedValue <T > for T where T :
183- tokio_postgres:: types:: FromSqlOwned
184- + tiberius:: FromSqlOwned
185- { }
186- } else if #[ cfg( all( feature = "mysql" , feature = "mssql" ) ) ] {
187- pub trait FromSql <' a, T >: mysql_async:: prelude:: FromValue
188- + tiberius:: FromSql <' a> { }
189- impl <' a, T > FromSql <' a, T > for T where T :
190- mysql_async:: prelude:: FromValue
191- + tiberius:: FromSql <' a>
192- { }
193-
194- pub trait FromSqlOwnedValue <T >: mysql_async:: prelude:: FromValue
195- + tiberius:: FromSqlOwned { }
196- impl <T > FromSqlOwnedValue <T > for T where T :
197- mysql_async:: prelude:: FromValue
198- + tiberius:: FromSqlOwned
199- { }
200- } else if #[ cfg( feature = "postgres" ) ] {
201- pub trait FromSql <' a, T >: tokio_postgres:: types:: FromSql <' a> { }
202- impl <' a, T > FromSql <' a, T > for T where T :
203- tokio_postgres:: types:: FromSql <' a> { }
204-
205- pub trait FromSqlOwnedValue <T >: tokio_postgres:: types:: FromSqlOwned { }
206- impl <T > FromSqlOwnedValue <T > for T where T :
207- tokio_postgres:: types:: FromSqlOwned { }
208- } else if #[ cfg( feature = "mysql" ) ] {
209- pub trait FromSql <' a, T >: mysql_async:: prelude:: FromValue { }
210- impl <' a, T > FromSql <' a, T > for T where T :
211- mysql_async:: prelude:: FromValue { }
212-
213- pub trait FromSqlOwnedValue <T >: mysql_async:: prelude:: FromValue { }
214- impl <T > FromSqlOwnedValue <T > for T where T :
215- mysql_async:: prelude:: FromValue { }
216- } else if #[ cfg( feature = "mssql" ) ] {
217- pub trait FromSql <' a, T >: tiberius:: FromSql <' a> { }
218- impl <' a, T > FromSql <' a, T > for T where T :
219- tiberius:: FromSql <' a> { }
220-
221- pub trait FromSqlOwnedValue <T >: tiberius:: FromSqlOwned { }
222- impl <T > FromSqlOwnedValue <T > for T where T :
223- tiberius:: FromSqlOwned { }
224- }
111+ pub trait FromSql < ' a > :
112+ __backend_from_sql:: PostgresFromSql < ' a >
113+ + __backend_from_sql:: MySqlFromSql
114+ + __backend_from_sql:: MsSqlFromSql < ' a >
115+ {
116+ }
117+
118+ impl < ' a , T > FromSql < ' a > for T where
119+ T : __backend_from_sql:: PostgresFromSql < ' a >
120+ + __backend_from_sql:: MySqlFromSql
121+ + __backend_from_sql:: MsSqlFromSql < ' a >
122+ {
123+ }
124+
125+ pub trait FromSqlOwnedValue :
126+ __backend_from_sql_owned:: PostgresFromSqlOwned
127+ + __backend_from_sql_owned:: MySqlFromSqlOwned
128+ + __backend_from_sql_owned:: MsSqlFromSqlOwned
129+ {
130+ }
131+
132+ impl < T > FromSqlOwnedValue for T where
133+ T : __backend_from_sql_owned:: PostgresFromSqlOwned
134+ + __backend_from_sql_owned:: MySqlFromSqlOwned
135+ + __backend_from_sql_owned:: MsSqlFromSqlOwned
136+ {
137+ }
138+
139+ #[ doc( hidden) ]
140+ pub mod __backend_from_sql {
141+ #[ cfg( feature = "postgres" ) ]
142+ pub trait PostgresFromSql < ' a > : tokio_postgres:: types:: FromSql < ' a > { }
143+
144+ #[ cfg( feature = "postgres" ) ]
145+ impl < ' a , T > PostgresFromSql < ' a > for T where T : tokio_postgres:: types:: FromSql < ' a > { }
146+
147+ #[ cfg( not( feature = "postgres" ) ) ]
148+ pub trait PostgresFromSql < ' a > { }
149+
150+ #[ cfg( not( feature = "postgres" ) ) ]
151+ impl < ' a , T > PostgresFromSql < ' a > for T { }
152+
153+ #[ cfg( feature = "mysql" ) ]
154+ pub trait MySqlFromSql : mysql_async:: prelude:: FromValue { }
155+
156+ #[ cfg( feature = "mysql" ) ]
157+ impl < T > MySqlFromSql for T where T : mysql_async:: prelude:: FromValue { }
158+
159+ #[ cfg( not( feature = "mysql" ) ) ]
160+ pub trait MySqlFromSql { }
161+
162+ #[ cfg( not( feature = "mysql" ) ) ]
163+ impl < T > MySqlFromSql for T { }
164+
165+ #[ cfg( feature = "mssql" ) ]
166+ pub trait MsSqlFromSql < ' a > : tiberius:: FromSql < ' a > { }
167+
168+ #[ cfg( feature = "mssql" ) ]
169+ impl < ' a , T > MsSqlFromSql < ' a > for T where T : tiberius:: FromSql < ' a > { }
170+
171+ #[ cfg( not( feature = "mssql" ) ) ]
172+ pub trait MsSqlFromSql < ' a > { }
173+
174+ #[ cfg( not( feature = "mssql" ) ) ]
175+ impl < ' a , T > MsSqlFromSql < ' a > for T { }
176+ }
177+
178+ #[ doc( hidden) ]
179+ pub mod __backend_from_sql_owned {
180+ #[ cfg( feature = "postgres" ) ]
181+ pub trait PostgresFromSqlOwned : tokio_postgres:: types:: FromSqlOwned { }
182+
183+ #[ cfg( feature = "postgres" ) ]
184+ impl < T > PostgresFromSqlOwned for T where T : tokio_postgres:: types:: FromSqlOwned { }
185+
186+ #[ cfg( not( feature = "postgres" ) ) ]
187+ pub trait PostgresFromSqlOwned { }
188+
189+ #[ cfg( not( feature = "postgres" ) ) ]
190+ impl < T > PostgresFromSqlOwned for T { }
191+
192+ #[ cfg( feature = "mysql" ) ]
193+ pub trait MySqlFromSqlOwned : mysql_async:: prelude:: FromValue { }
194+
195+ #[ cfg( feature = "mysql" ) ]
196+ impl < T > MySqlFromSqlOwned for T where T : mysql_async:: prelude:: FromValue { }
197+
198+ #[ cfg( not( feature = "mysql" ) ) ]
199+ pub trait MySqlFromSqlOwned { }
200+
201+ #[ cfg( not( feature = "mysql" ) ) ]
202+ impl < T > MySqlFromSqlOwned for T { }
203+
204+ #[ cfg( feature = "mssql" ) ]
205+ pub trait MsSqlFromSqlOwned : tiberius:: FromSqlOwned { }
206+
207+ #[ cfg( feature = "mssql" ) ]
208+ impl < T > MsSqlFromSqlOwned for T where T : tiberius:: FromSqlOwned { }
209+
210+ #[ cfg( not( feature = "mssql" ) ) ]
211+ pub trait MsSqlFromSqlOwned { }
212+
213+ #[ cfg( not( feature = "mssql" ) ) ]
214+ impl < T > MsSqlFromSqlOwned for T { }
225215}
0 commit comments