1#[cfg(feature = "libsql")]
20mod libsql;
21#[cfg(any(feature = "tokio-postgres", feature = "postgres-sync"))]
22mod postgres;
23#[cfg(feature = "rusqlite")]
24mod rusqlite;
25#[cfg(any(feature = "rusqlite", feature = "libsql", feature = "turso"))]
29pub(crate) mod sqlite_value;
30#[cfg(feature = "turso")]
31mod turso;
32
33use core::marker::PhantomData;
34
35use crate::error::DrizzleError;
36use crate::{Cons, Nil};
37
38#[derive(Debug, Clone, Copy, Default)]
44pub struct SelectStar;
45
46#[derive(Debug, Clone, Copy, Default)]
48pub struct SelectCols<Cols>(PhantomData<Cols>);
49
50#[derive(Debug, Clone, Copy, Default)]
52pub struct SelectExpr;
53
54#[derive(Debug, Clone, Copy, Default)]
56pub struct SelectAs<R>(PhantomData<R>);
57
58#[derive(Debug, Clone, Copy, Default)]
60pub struct Scoped<Marker, Scope>(PhantomData<(Marker, Scope)>);
61
62pub trait SelectRequiredTables {
64 type RequiredTables;
65}
66
67#[derive(Debug, Clone, Copy, Default)]
69pub struct ScopeHere;
70
71#[derive(Debug, Clone, Copy, Default)]
73pub struct ScopeThere<Prev>(PhantomData<Prev>);
74
75pub trait ScopeContains<Table, Witness> {}
77
78impl<Head, Tail> ScopeContains<Head, ScopeHere> for Cons<Head, Tail> {}
79
80impl<Head, Tail, Table, Witness> ScopeContains<Table, ScopeThere<Witness>> for Cons<Head, Tail> where
81 Tail: ScopeContains<Table, Witness>
82{
83}
84
85pub trait ScopeSatisfies<Required, Proof> {}
87
88impl<Scope> ScopeSatisfies<Nil, ()> for Scope {}
89
90impl<Scope, Head, Tail, HeadProof, TailProof>
91 ScopeSatisfies<Cons<Head, Tail>, (HeadProof, TailProof)> for Scope
92where
93 Scope: ScopeContains<Head, HeadProof> + ScopeSatisfies<Tail, TailProof>,
94{
95}
96
97pub trait MarkerRequiredTables {
99 type RequiredTables;
100}
101
102impl MarkerRequiredTables for SelectStar {
103 type RequiredTables = Nil;
104}
105
106impl<Cols> MarkerRequiredTables for SelectCols<Cols> {
107 type RequiredTables = Nil;
108}
109
110impl MarkerRequiredTables for SelectExpr {
111 type RequiredTables = Nil;
112}
113
114impl<R> MarkerRequiredTables for SelectAs<R>
115where
116 R: SelectRequiredTables,
117{
118 type RequiredTables = R::RequiredTables;
119}
120
121#[diagnostic::on_unimplemented(
123 message = "selected row requires tables not present in the current query scope",
124 label = "add .join(...) entries for every table referenced by this selector",
125 note = "for aliased selectors, use the same alias type in #[from(...)] and .from(...)"
126)]
127pub trait MarkerScopeValidFor<Proof> {}
169
170impl<M, Scope, Proof> MarkerScopeValidFor<Proof> for Scoped<M, Scope>
171where
172 M: MarkerRequiredTables,
173 Scope: ScopeSatisfies<<M as MarkerRequiredTables>::RequiredTables, Proof>,
174{
175}
176
177pub trait AggStatus {
186 type Status;
187}
188
189impl<E: crate::expr::HasAggStatus> AggStatus for (E,) {
191 type Status = E::Status;
192}
193
194macro_rules! impl_tuple_agg_status {
199 ($E0:ident; $i0:tt) => {};
201 ($E0:ident, $E1:ident; $i0:tt, $i1:tt) => {
203 impl<$E0, $E1> AggStatus for ($E0, $E1)
204 where
205 $E0: crate::expr::HasAggStatus,
206 $E1: crate::expr::HasAggStatus,
207 <$E0 as crate::expr::HasAggStatus>::Status:
208 crate::expr::CombineAggStatus<<$E1 as crate::expr::HasAggStatus>::Status>,
209 {
210 type Status = <<$E0 as crate::expr::HasAggStatus>::Status as
211 crate::expr::CombineAggStatus<<$E1 as crate::expr::HasAggStatus>::Status>>::Output;
212 }
213 };
214 ($E0:ident, $E1:ident, $($rest:ident),+; $i0:tt, $i1:tt, $($ri:tt),+) => {
216 impl<$E0, $E1, $($rest),+> AggStatus for ($E0, $E1, $($rest),+)
217 where
218 $E0: crate::expr::HasAggStatus,
219 ($E1, $($rest),+): AggStatus,
220 <$E0 as crate::expr::HasAggStatus>::Status:
221 crate::expr::CombineAggStatus<<($E1, $($rest),+) as AggStatus>::Status>,
222 {
223 type Status = <<$E0 as crate::expr::HasAggStatus>::Status as
224 crate::expr::CombineAggStatus<<($E1, $($rest),+) as AggStatus>::Status>>::Output;
225 }
226 };
227}
228
229with_col_sizes_8!(impl_tuple_agg_status);
230
231#[cfg(any(
232 feature = "col16",
233 feature = "col32",
234 feature = "col64",
235 feature = "col128",
236 feature = "col200"
237))]
238with_col_sizes_16!(impl_tuple_agg_status);
239
240#[cfg(any(
241 feature = "col32",
242 feature = "col64",
243 feature = "col128",
244 feature = "col200"
245))]
246with_col_sizes_32!(impl_tuple_agg_status);
247
248#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
249with_col_sizes_64!(impl_tuple_agg_status);
250
251#[cfg(any(feature = "col128", feature = "col200"))]
252with_col_sizes_128!(impl_tuple_agg_status);
253
254#[cfg(feature = "col200")]
255with_col_sizes_200!(impl_tuple_agg_status);
256
257pub trait IntoGroupBy<'a, V: crate::SQLParam + 'a>: crate::ToSQL<'a, V> {
267 type Columns;
269}
270
271macro_rules! impl_into_group_by_tuple {
276 ($T0:ident; $i0:tt) => {};
278 ($T0:ident, $T1:ident; $i0:tt, $i1:tt) => {
280 impl<'a, V: crate::SQLParam + 'a, $T0, $T1> IntoGroupBy<'a, V> for ($T0, $T1)
281 where
282 $T0: crate::ToSQL<'a, V>,
283 $T1: crate::ToSQL<'a, V>,
284 {
285 type Columns = Cons<$T0, Cons<$T1, Nil>>;
286 }
287 };
288 ($T0:ident, $T1:ident, $($rest:ident),+; $i0:tt, $i1:tt, $($ri:tt),+) => {
290 impl<'a, V: crate::SQLParam + 'a, $T0, $T1, $($rest),+> IntoGroupBy<'a, V> for ($T0, $T1, $($rest),+)
291 where
292 $T0: crate::ToSQL<'a, V>,
293 $T1: crate::ToSQL<'a, V>,
294 $($rest: crate::ToSQL<'a, V>,)+
295 {
296 type Columns = impl_into_group_by_tuple!(@cons $T0, $T1, $($rest),+);
297 }
298 };
299 (@cons $T:ident) => { Cons<$T, Nil> };
301 (@cons $T:ident, $($rest:ident),+) => { Cons<$T, impl_into_group_by_tuple!(@cons $($rest),+)> };
302}
303
304with_col_sizes_8!(impl_into_group_by_tuple);
305
306#[cfg(any(
307 feature = "col16",
308 feature = "col32",
309 feature = "col64",
310 feature = "col128",
311 feature = "col200"
312))]
313with_col_sizes_16!(impl_into_group_by_tuple);
314
315#[diagnostic::on_unimplemented(
324 message = "non-aggregate column in SELECT is not in GROUP BY",
325 label = "this column must appear in .group_by(...) or be wrapped in an aggregate function",
326 note = "when using GROUP BY, every non-aggregate column in SELECT must be listed in GROUP BY"
327)]
328pub trait ScalarColumnsIn<Grouped, Proof> {}
329
330pub struct AggSkip;
332
333pub struct ScalarCheck<W>(core::marker::PhantomData<W>);
335
336impl<E, Grouped, Proof> ScalarColumnsIn<Grouped, (Proof,)> for (E,) where
338 E: SingleColGroupCheck<Grouped, Proof>
339{
340}
341
342pub trait SingleColGroupCheck<Grouped, Proof> {}
344
345pub trait GroupByIdentity {
349 type Identity;
350}
351
352impl<E: GroupByIdentity> GroupByIdentity for crate::expr::AliasedExpr<E> {
357 type Identity = E::Identity;
358}
359
360impl<V: crate::SQLParam, T, N, A> GroupByIdentity for crate::expr::SQLExpr<'_, V, T, N, A>
362where
363 T: crate::types::DataType,
364 N: crate::expr::Nullability,
365 A: crate::expr::AggregateKind,
366{
367 type Identity = Self;
368}
369
370impl<Lhs, Rhs, Op> GroupByIdentity for crate::expr::ColumnBinOp<Lhs, Rhs, Op> {
372 type Identity = Self;
373}
374
375impl<T> GroupByIdentity for crate::expr::ColumnNeg<T> {
377 type Identity = Self;
378}
379
380impl<E, Grouped> SingleColGroupCheck<Grouped, AggSkip> for E where
382 E: crate::expr::HasAggStatus<Status = crate::expr::AllAgg>
383{
384}
385
386impl<E, Grouped, W> SingleColGroupCheck<Grouped, ScalarCheck<W>> for E
388where
389 E: crate::expr::HasAggStatus<Status = crate::expr::AllScalar> + GroupByIdentity,
390 Grouped: ScopeContains<E::Identity, W>,
391{
392}
393
394impl<T0, T1, Grouped, P0, P1> ScalarColumnsIn<Grouped, (P0, P1)> for (T0, T1)
399where
400 T0: SingleColGroupCheck<Grouped, P0>,
401 T1: SingleColGroupCheck<Grouped, P1>,
402{
403}
404
405macro_rules! impl_scalar_columns_in {
407 ($T0:ident; $i0:tt) => {};
409 ($T0:ident, $T1:ident; $i0:tt, $i1:tt) => {};
411 ($T0:ident, $($rest:ident),+; $i0:tt, $($ri:tt),+) => {
413 impl<$T0, $($rest),+, Grouped, HeadProof, TailProof>
414 ScalarColumnsIn<Grouped, (HeadProof, TailProof)>
415 for ($T0, $($rest),+)
416 where
417 $T0: SingleColGroupCheck<Grouped, HeadProof>,
418 ($($rest,)+): ScalarColumnsIn<Grouped, TailProof>,
419 {}
420 };
421}
422
423with_col_sizes_8!(impl_scalar_columns_in);
424
425#[cfg(any(
426 feature = "col16",
427 feature = "col32",
428 feature = "col64",
429 feature = "col128",
430 feature = "col200"
431))]
432with_col_sizes_16!(impl_scalar_columns_in);
433
434#[diagnostic::on_unimplemented(
443 message = "non-aggregate column in SELECT is not in GROUP BY",
444 label = "add this column to .group_by(...) or wrap it in an aggregate function"
445)]
446pub trait MarkerAggValidFor<Grouped, Proof = ()> {}
447
448impl<Mk> MarkerAggValidFor<()> for Mk {}
450
451impl<Scope, Head, Tail> MarkerAggValidFor<Cons<Head, Tail>> for Scoped<SelectStar, Scope> {}
453
454impl<Scope, Head, Tail> MarkerAggValidFor<Cons<Head, Tail>> for Scoped<SelectExpr, Scope> {}
456
457impl<Scope, R, Head, Tail> MarkerAggValidFor<Cons<Head, Tail>> for Scoped<SelectAs<R>, Scope> {}
459
460impl<Scope, Cols, Head, Tail, Proof> MarkerAggValidFor<Cons<Head, Tail>, Proof>
462 for Scoped<SelectCols<Cols>, Scope>
463where
464 Cols: ScalarColumnsIn<Cons<Head, Tail>, Proof>,
465{
466}
467
468pub trait RowColumnList<Row: ?Sized> {
477 type Columns: crate::TypeSet;
478}
479
480pub trait SelectedColumnList {
482 type Columns: crate::TypeSet;
483}
484
485trait SameType<T> {}
486impl<T> SameType<T> for T {}
487
488trait ColumnTypeCompatible<Row: ?Sized, Expected, Actual> {}
489
490impl<Row: ?Sized, T> ColumnTypeCompatible<Row, T, T> for () {}
491
492trait TypeListCompatible<Row: ?Sized, ActualList> {}
493
494impl<Row: ?Sized> TypeListCompatible<Row, Self> for crate::Nil {}
495
496impl<Row: ?Sized, EH, ET, AH, AT> TypeListCompatible<Row, crate::Cons<AH, AT>>
497 for crate::Cons<EH, ET>
498where
499 (): ColumnTypeCompatible<Row, EH, AH>,
500 ET: TypeListCompatible<Row, AT>,
501{
502}
503
504trait SqliteDecodeRow {}
505
506#[cfg(feature = "rusqlite")]
507impl SqliteDecodeRow for ::rusqlite::Row<'_> {}
508
509#[cfg(feature = "libsql")]
510impl SqliteDecodeRow for ::libsql::Row {}
511
512#[cfg(feature = "turso")]
513impl SqliteDecodeRow for ::turso::Row {}
514
515macro_rules! impl_sqlite_integer_decode_compat {
516 ($expected:ty => $($actual:ty),+ $(,)?) => {
517 $(
518 impl<Row> ColumnTypeCompatible<Row, $expected, $actual> for ()
519 where
520 Row: SqliteDecodeRow,
521 {
522 }
523 )+
524 };
525}
526
527impl_sqlite_integer_decode_compat!(
528 i64 => i8, i16, i32, isize, u8, u16, u32, u64, usize, bool
529);
530
531impl_sqlite_integer_decode_compat!(
532 Option<i64> =>
533 Option<i8>,
534 Option<i16>,
535 Option<i32>,
536 Option<isize>,
537 Option<u8>,
538 Option<u16>,
539 Option<u32>,
540 Option<u64>,
541 Option<usize>,
542 Option<bool>
543);
544
545macro_rules! impl_row_column_list_one {
546 ($($ty:ty),+ $(,)?) => {
547 $(
548 impl<Row: ?Sized> RowColumnList<Row> for $ty {
549 type Columns = crate::Cons<$ty, crate::Nil>;
550 }
551 )+
552 };
553}
554
555impl_row_column_list_one!(
556 i8,
557 i16,
558 i32,
559 i64,
560 isize,
561 u8,
562 u16,
563 u32,
564 u64,
565 usize,
566 f32,
567 f64,
568 bool,
569 crate::prelude::String,
570 crate::prelude::Vec<u8>
571);
572
573impl<Row: ?Sized> RowColumnList<Row> for () {
574 type Columns = crate::Cons<(), crate::Nil>;
575}
576
577#[cfg(feature = "uuid")]
578impl<Row: ?Sized> RowColumnList<Row> for uuid::Uuid {
579 type Columns = crate::Cons<Self, crate::Nil>;
580}
581
582#[cfg(feature = "chrono")]
583impl<Row: ?Sized> RowColumnList<Row> for chrono::NaiveDate {
584 type Columns = crate::Cons<Self, crate::Nil>;
585}
586
587#[cfg(feature = "chrono")]
588impl<Row: ?Sized> RowColumnList<Row> for chrono::NaiveTime {
589 type Columns = crate::Cons<Self, crate::Nil>;
590}
591
592#[cfg(feature = "chrono")]
593impl<Row: ?Sized> RowColumnList<Row> for chrono::NaiveDateTime {
594 type Columns = crate::Cons<Self, crate::Nil>;
595}
596
597#[cfg(feature = "chrono")]
598impl<Row: ?Sized> RowColumnList<Row> for chrono::DateTime<chrono::Utc> {
599 type Columns = crate::Cons<Self, crate::Nil>;
600}
601
602#[cfg(feature = "serde")]
603impl<Row: ?Sized> RowColumnList<Row> for serde_json::Value {
604 type Columns = crate::Cons<Self, crate::Nil>;
605}
606
607#[cfg(feature = "rust-decimal")]
608impl<Row: ?Sized> RowColumnList<Row> for rust_decimal::Decimal {
609 type Columns = crate::Cons<Self, crate::Nil>;
610}
611
612#[cfg(feature = "chrono")]
613impl<Row: ?Sized> RowColumnList<Row> for chrono::Duration {
614 type Columns = crate::Cons<Self, crate::Nil>;
615}
616
617#[cfg(feature = "cidr")]
618impl<Row: ?Sized> RowColumnList<Row> for cidr::IpInet {
619 type Columns = crate::Cons<Self, crate::Nil>;
620}
621
622#[cfg(feature = "cidr")]
623impl<Row: ?Sized> RowColumnList<Row> for cidr::IpCidr {
624 type Columns = crate::Cons<Self, crate::Nil>;
625}
626
627#[cfg(feature = "geo-types")]
628impl<Row: ?Sized> RowColumnList<Row> for geo_types::Point<f64> {
629 type Columns = crate::Cons<Self, crate::Nil>;
630}
631
632#[cfg(feature = "geo-types")]
633impl<Row: ?Sized> RowColumnList<Row> for geo_types::LineString<f64> {
634 type Columns = crate::Cons<Self, crate::Nil>;
635}
636
637#[cfg(feature = "geo-types")]
638impl<Row: ?Sized> RowColumnList<Row> for geo_types::Rect<f64> {
639 type Columns = crate::Cons<Self, crate::Nil>;
640}
641
642#[cfg(feature = "bit-vec")]
643impl<Row: ?Sized> RowColumnList<Row> for bit_vec::BitVec {
644 type Columns = crate::Cons<Self, crate::Nil>;
645}
646
647#[cfg(feature = "arrayvec")]
648impl<Row: ?Sized, const N: usize> RowColumnList<Row> for arrayvec::ArrayString<N> {
649 type Columns = crate::Cons<Self, crate::Nil>;
650}
651
652#[cfg(feature = "arrayvec")]
653impl<Row: ?Sized, T, const N: usize> RowColumnList<Row> for arrayvec::ArrayVec<T, N> {
654 type Columns = crate::Cons<Self, crate::Nil>;
655}
656
657impl<Row: ?Sized> RowColumnList<Row> for compact_str::CompactString {
658 type Columns = crate::Cons<Self, crate::Nil>;
659}
660
661#[cfg(feature = "bytes")]
662impl<Row: ?Sized> RowColumnList<Row> for bytes::Bytes {
663 type Columns = crate::Cons<Self, crate::Nil>;
664}
665
666#[cfg(feature = "bytes")]
667impl<Row: ?Sized> RowColumnList<Row> for bytes::BytesMut {
668 type Columns = crate::Cons<Self, crate::Nil>;
669}
670
671impl<Row: ?Sized, A: smallvec::Array> RowColumnList<Row> for smallvec::SmallVec<A> {
672 type Columns = crate::Cons<Self, crate::Nil>;
673}
674
675impl<Row: ?Sized, T> RowColumnList<Row> for Option<T> {
676 type Columns = crate::Cons<Self, crate::Nil>;
677}
678
679impl<Row: ?Sized, A> RowColumnList<Row> for (A,)
680where
681 A: RowColumnList<Row>,
682{
683 type Columns = <A as RowColumnList<Row>>::Columns;
684}
685
686impl<Row: ?Sized, A, B> RowColumnList<Row> for (A, B)
687where
688 A: RowColumnList<Row>,
689 B: RowColumnList<Row>,
690 <A as RowColumnList<Row>>::Columns: crate::Concat<<B as RowColumnList<Row>>::Columns>,
691{
692 type Columns = <<A as RowColumnList<Row>>::Columns as crate::Concat<
693 <B as RowColumnList<Row>>::Columns,
694 >>::Output;
695}
696
697impl<Row: ?Sized, A, B, C> RowColumnList<Row> for (A, B, C)
698where
699 A: RowColumnList<Row>,
700 B: RowColumnList<Row>,
701 C: RowColumnList<Row>,
702 <A as RowColumnList<Row>>::Columns: crate::Concat<<B as RowColumnList<Row>>::Columns>,
703 <<A as RowColumnList<Row>>::Columns as crate::Concat<<B as RowColumnList<Row>>::Columns>>::Output:
704 crate::Concat<<C as RowColumnList<Row>>::Columns>,
705{
706 type Columns = <<<A as RowColumnList<Row>>::Columns as crate::Concat<
707 <B as RowColumnList<Row>>::Columns,
708 >>::Output as crate::Concat<<C as RowColumnList<Row>>::Columns>>::Output;
709}
710
711impl<Row: ?Sized, A, B, C, D> RowColumnList<Row> for (A, B, C, D)
712where
713 A: RowColumnList<Row>,
714 B: RowColumnList<Row>,
715 C: RowColumnList<Row>,
716 D: RowColumnList<Row>,
717 (A, B, C): RowColumnList<Row>,
718 <(A, B, C) as RowColumnList<Row>>::Columns: crate::Concat<<D as RowColumnList<Row>>::Columns>,
719{
720 type Columns = <<(A, B, C) as RowColumnList<Row>>::Columns as crate::Concat<
721 <D as RowColumnList<Row>>::Columns,
722 >>::Output;
723}
724
725impl<Row: ?Sized, A, B, C, D, E> RowColumnList<Row> for (A, B, C, D, E)
726where
727 E: RowColumnList<Row>,
728 (A, B, C, D): RowColumnList<Row>,
729 <(A, B, C, D) as RowColumnList<Row>>::Columns:
730 crate::Concat<<E as RowColumnList<Row>>::Columns>,
731{
732 type Columns = <<(A, B, C, D) as RowColumnList<Row>>::Columns as crate::Concat<
733 <E as RowColumnList<Row>>::Columns,
734 >>::Output;
735}
736
737impl<Row: ?Sized, A, B, C, D, E, F> RowColumnList<Row> for (A, B, C, D, E, F)
738where
739 F: RowColumnList<Row>,
740 (A, B, C, D, E): RowColumnList<Row>,
741 <(A, B, C, D, E) as RowColumnList<Row>>::Columns:
742 crate::Concat<<F as RowColumnList<Row>>::Columns>,
743{
744 type Columns = <<(A, B, C, D, E) as RowColumnList<Row>>::Columns as crate::Concat<
745 <F as RowColumnList<Row>>::Columns,
746 >>::Output;
747}
748
749impl<Row: ?Sized, A, B, C, D, E, F, G> RowColumnList<Row> for (A, B, C, D, E, F, G)
750where
751 G: RowColumnList<Row>,
752 (A, B, C, D, E, F): RowColumnList<Row>,
753 <(A, B, C, D, E, F) as RowColumnList<Row>>::Columns:
754 crate::Concat<<G as RowColumnList<Row>>::Columns>,
755{
756 type Columns = <<(A, B, C, D, E, F) as RowColumnList<Row>>::Columns as crate::Concat<
757 <G as RowColumnList<Row>>::Columns,
758 >>::Output;
759}
760
761impl<Row: ?Sized, A, B, C, D, E, F, G, H> RowColumnList<Row> for (A, B, C, D, E, F, G, H)
762where
763 H: RowColumnList<Row>,
764 (A, B, C, D, E, F, G): RowColumnList<Row>,
765 <(A, B, C, D, E, F, G) as RowColumnList<Row>>::Columns:
766 crate::Concat<<H as RowColumnList<Row>>::Columns>,
767{
768 type Columns = <<(A, B, C, D, E, F, G) as RowColumnList<Row>>::Columns as crate::Concat<
769 <H as RowColumnList<Row>>::Columns,
770 >>::Output;
771}
772
773#[diagnostic::on_unimplemented(
777 message = "selected shape does not match decode target `{Actual}`",
778 label = "this decode target is not type-compatible with .select(...) output",
779 note = "use typed expressions or derive FromRow for explicit remapping when selecting custom expressions"
780)]
781pub trait MarkerColumnCountValid<Row: ?Sized, Inferred, Actual> {}
782
783#[diagnostic::on_unimplemented(
789 message = "raw select expressions require explicit typing in strict decode",
790 label = "`select(sql!(...)).all()/get()` is not allowed in strict mode",
791 note = "use typed wrappers like `raw_non_null`/`raw_nullable` or derive FromRow"
792)]
793pub trait StrictDecodeMarker {}
794
795impl StrictDecodeMarker for SelectStar {}
796impl<Cols> StrictDecodeMarker for SelectCols<Cols> {}
797impl<R> StrictDecodeMarker for SelectAs<R> {}
798impl<M, Scope> StrictDecodeMarker for Scoped<M, Scope> where M: StrictDecodeMarker {}
799
800impl<Row: ?Sized, Inferred, Actual> MarkerColumnCountValid<Row, Inferred, Actual> for SelectStar {}
801
802impl<Row: ?Sized, Cols, Inferred, Actual> MarkerColumnCountValid<Row, Inferred, Actual>
803 for SelectCols<Cols>
804where
805 Cols: SelectedColumnList,
806 Actual: RowColumnList<Row>,
807 <Cols as SelectedColumnList>::Columns:
808 TypeListCompatible<Row, <Actual as RowColumnList<Row>>::Columns>,
809{
810}
811
812impl<Row: ?Sized, Inferred, Actual> MarkerColumnCountValid<Row, Inferred, Actual> for SelectExpr where
813 Inferred: SameType<Actual>
814{
815}
816
817impl<Row: ?Sized, R, Inferred, Actual> MarkerColumnCountValid<Row, Inferred, Actual>
818 for SelectAs<R>
819{
820}
821
822impl<M, Scope, Row: ?Sized, Inferred, Actual> MarkerColumnCountValid<Row, Inferred, Actual>
823 for Scoped<M, Scope>
824where
825 M: MarkerColumnCountValid<Row, Inferred, Actual>,
826{
827}
828
829pub trait ScopePush<Joined> {
831 type Out;
832}
833
834impl<M, Scope, Joined> ScopePush<Joined> for Scoped<M, Scope> {
835 type Out = Scoped<M, Cons<Joined, Scope>>;
836}
837
838pub trait DecodeSelectedRef<RowRef, R> {
840 fn decode(row: RowRef) -> Result<R, DrizzleError>;
847}
848
849impl<RowRef, R> DecodeSelectedRef<RowRef, R> for SelectAs<R>
850where
851 R: TryFrom<RowRef>,
852 <R as TryFrom<RowRef>>::Error: Into<DrizzleError>,
853{
854 fn decode(row: RowRef) -> Result<R, DrizzleError> {
855 R::try_from(row).map_err(Into::into)
856 }
857}
858
859impl<RowRef, R, M, Scope> DecodeSelectedRef<RowRef, R> for Scoped<M, Scope>
860where
861 M: DecodeSelectedRef<RowRef, R>,
862{
863 fn decode(row: RowRef) -> Result<R, DrizzleError> {
864 M::decode(row)
865 }
866}
867
868impl<RowRef, Row: ?Sized, R> DecodeSelectedRef<RowRef, R> for SelectStar
869where
870 RowRef: core::ops::Deref<Target = Row>,
871 R: FromDrizzleRow<Row>,
872{
873 fn decode(row: RowRef) -> Result<R, DrizzleError> {
874 R::from_row(&*row)
875 }
876}
877
878impl<RowRef, Row: ?Sized, Cols, R> DecodeSelectedRef<RowRef, R> for SelectCols<Cols>
879where
880 RowRef: core::ops::Deref<Target = Row>,
881 R: FromDrizzleRow<Row>,
882{
883 fn decode(row: RowRef) -> Result<R, DrizzleError> {
884 R::from_row(&*row)
885 }
886}
887
888impl<RowRef, Row: ?Sized, R> DecodeSelectedRef<RowRef, R> for SelectExpr
889where
890 RowRef: core::ops::Deref<Target = Row>,
891 R: FromDrizzleRow<Row>,
892{
893 fn decode(row: RowRef) -> Result<R, DrizzleError> {
894 R::from_row(&*row)
895 }
896}
897
898#[diagnostic::on_unimplemented(
910 message = "cannot deserialize `{Self}` from a database row",
911 label = "this type does not implement FromDrizzleRow",
912 note = "derive #[SQLiteFromRow] or #[PostgresFromRow]"
913)]
914pub trait FromDrizzleRow<Row: ?Sized>: Sized {
915 const COLUMN_COUNT: usize;
917
918 fn from_row_at(row: &Row, offset: usize) -> Result<Self, DrizzleError>;
925
926 fn from_row(row: &Row) -> Result<Self, DrizzleError> {
932 Self::from_row_at(row, 0)
933 }
934}
935
936pub trait NullProbeRow<Row: ?Sized>: FromDrizzleRow<Row> {
945 fn is_null_at(row: &Row, offset: usize) -> Result<bool, DrizzleError>;
952}
953
954macro_rules! impl_from_drizzle_row_tuple {
957 ($($T:ident),+; $($idx:tt),+) => {
958 impl<__Row: ?Sized, $($T: FromDrizzleRow<__Row>),+> FromDrizzleRow<__Row> for ($($T,)+) {
959 const COLUMN_COUNT: usize = 0 $(+ <$T as FromDrizzleRow<__Row>>::COLUMN_COUNT)+;
960
961 #[allow(non_snake_case)]
962 fn from_row_at(
963 row: &__Row,
964 offset: usize,
965 ) -> Result<Self, DrizzleError> {
966 let mut __off = offset;
967 $(
968 let $T = <$T as FromDrizzleRow<__Row>>::from_row_at(row, __off)?;
969 __off += <$T as FromDrizzleRow<__Row>>::COLUMN_COUNT;
970 )+
971 Ok(($($T,)+))
972 }
973 }
974 };
975}
976
977with_col_sizes_8!(impl_from_drizzle_row_tuple);
978
979#[cfg(any(
980 feature = "col16",
981 feature = "col32",
982 feature = "col64",
983 feature = "col128",
984 feature = "col200"
985))]
986with_col_sizes_16!(impl_from_drizzle_row_tuple);
987
988#[cfg(any(
989 feature = "col32",
990 feature = "col64",
991 feature = "col128",
992 feature = "col200"
993))]
994with_col_sizes_32!(impl_from_drizzle_row_tuple);
995
996#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
997with_col_sizes_64!(impl_from_drizzle_row_tuple);
998
999#[cfg(any(feature = "col128", feature = "col200"))]
1000with_col_sizes_128!(impl_from_drizzle_row_tuple);
1001
1002#[cfg(feature = "col200")]
1003with_col_sizes_200!(impl_from_drizzle_row_tuple);
1004
1005#[diagnostic::on_unimplemented(
1023 message = "SQL type `{Self}` has no default Rust mapping for dialect `{D}`",
1024 label = "this SQL type has no default Rust mapping for this dialect",
1025 note = "enable `chrono` for Date/Time/Timestamp/TimestampTz, `uuid` for Uuid, or `serde` for Json/Jsonb"
1026)]
1027pub trait SQLTypeToRust<D> {
1028 type RustType;
1029}
1030
1031use crate::dialect::{PostgresDialect, SQLiteDialect};
1034
1035impl<D, T> SQLTypeToRust<D> for crate::types::Array<T>
1036where
1037 T: crate::types::DataType + SQLTypeToRust<D>,
1038{
1039 type RustType = crate::prelude::Vec<<T as SQLTypeToRust<D>>::RustType>;
1040}
1041
1042impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Integer {
1043 type RustType = i64;
1044}
1045
1046impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Text {
1047 type RustType = crate::prelude::String;
1048}
1049
1050impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Real {
1051 type RustType = f64;
1052}
1053
1054impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Blob {
1055 type RustType = crate::prelude::Vec<u8>;
1056}
1057
1058impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Numeric {
1059 type RustType = f64;
1060}
1061
1062impl SQLTypeToRust<SQLiteDialect> for drizzle_types::sqlite::types::Any {
1063 type RustType = crate::prelude::String;
1064}
1065
1066impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Int2 {
1067 type RustType = i16;
1068}
1069
1070impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Int4 {
1071 type RustType = i32;
1072}
1073
1074impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Int8 {
1075 type RustType = i64;
1076}
1077
1078impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Float4 {
1079 type RustType = f32;
1080}
1081
1082impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Float8 {
1083 type RustType = f64;
1084}
1085
1086impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Varchar {
1087 type RustType = crate::prelude::String;
1088}
1089
1090impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Text {
1091 type RustType = crate::prelude::String;
1092}
1093
1094impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Char {
1095 type RustType = crate::prelude::String;
1096}
1097
1098impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Bytea {
1099 type RustType = crate::prelude::Vec<u8>;
1100}
1101
1102impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Boolean {
1103 type RustType = bool;
1104}
1105
1106#[cfg(feature = "rust-decimal")]
1107impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Numeric {
1108 type RustType = rust_decimal::Decimal;
1109}
1110
1111#[cfg(not(feature = "rust-decimal"))]
1112impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Numeric {
1113 type RustType = crate::prelude::String;
1114}
1115
1116impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Any {
1117 type RustType = crate::prelude::String;
1118}
1119
1120#[cfg(feature = "chrono")]
1121impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Timestamptz {
1122 type RustType = chrono::DateTime<chrono::Utc>;
1123}
1124
1125#[cfg(feature = "chrono")]
1126impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Timestamp {
1127 type RustType = chrono::NaiveDateTime;
1128}
1129
1130#[cfg(feature = "chrono")]
1131impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Date {
1132 type RustType = chrono::NaiveDate;
1133}
1134
1135#[cfg(feature = "chrono")]
1136impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Time {
1137 type RustType = chrono::NaiveTime;
1138}
1139
1140#[cfg(feature = "chrono")]
1141impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Timetz {
1142 type RustType = chrono::NaiveTime;
1143}
1144
1145#[cfg(feature = "uuid")]
1146impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Uuid {
1147 type RustType = uuid::Uuid;
1148}
1149
1150#[cfg(feature = "serde")]
1151impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Json {
1152 type RustType = serde_json::Value;
1153}
1154
1155#[cfg(feature = "serde")]
1156impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Jsonb {
1157 type RustType = serde_json::Value;
1158}
1159
1160#[cfg(feature = "chrono")]
1163impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Interval {
1164 type RustType = chrono::Duration;
1165}
1166
1167#[cfg(not(feature = "chrono"))]
1168impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Interval {
1169 type RustType = crate::prelude::String;
1170}
1171
1172#[cfg(feature = "cidr")]
1173impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Inet {
1174 type RustType = cidr::IpInet;
1175}
1176
1177#[cfg(not(feature = "cidr"))]
1178impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Inet {
1179 type RustType = crate::prelude::String;
1180}
1181
1182#[cfg(feature = "cidr")]
1183impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Cidr {
1184 type RustType = cidr::IpCidr;
1185}
1186
1187#[cfg(not(feature = "cidr"))]
1188impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Cidr {
1189 type RustType = crate::prelude::String;
1190}
1191
1192impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::MacAddr {
1193 type RustType = crate::prelude::String;
1194}
1195
1196impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::MacAddr8 {
1197 type RustType = crate::prelude::String;
1198}
1199
1200#[cfg(feature = "geo-types")]
1201impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Point {
1202 type RustType = geo_types::Point<f64>;
1203}
1204
1205#[cfg(not(feature = "geo-types"))]
1206impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Point {
1207 type RustType = crate::prelude::String;
1208}
1209
1210#[cfg(feature = "geo-types")]
1211impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::LineString {
1212 type RustType = geo_types::LineString<f64>;
1213}
1214
1215#[cfg(not(feature = "geo-types"))]
1216impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::LineString {
1217 type RustType = crate::prelude::String;
1218}
1219
1220#[cfg(feature = "geo-types")]
1221impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Rect {
1222 type RustType = geo_types::Rect<f64>;
1223}
1224
1225#[cfg(not(feature = "geo-types"))]
1226impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Rect {
1227 type RustType = crate::prelude::String;
1228}
1229
1230#[cfg(feature = "bit-vec")]
1231impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::BitString {
1232 type RustType = bit_vec::BitVec;
1233}
1234
1235#[cfg(not(feature = "bit-vec"))]
1236impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::BitString {
1237 type RustType = crate::prelude::String;
1238}
1239
1240impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Line {
1241 type RustType = crate::prelude::String;
1242}
1243
1244impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::LineSegment {
1245 type RustType = crate::prelude::String;
1246}
1247
1248impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Polygon {
1249 type RustType = crate::prelude::String;
1250}
1251
1252impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Circle {
1253 type RustType = crate::prelude::String;
1254}
1255
1256impl SQLTypeToRust<PostgresDialect> for drizzle_types::postgres::types::Enum {
1257 type RustType = crate::prelude::String;
1258}
1259
1260pub trait WrapNullable<T> {
1266 type Output;
1267}
1268
1269impl<T> WrapNullable<T> for crate::expr::NonNull {
1270 type Output = T;
1271}
1272
1273impl<T> WrapNullable<T> for crate::expr::Null {
1274 type Output = Option<T>;
1275}
1276
1277#[diagnostic::on_unimplemented(
1290 message = "cannot infer Rust type for expression `{Self}`",
1291 label = "use typed expressions or derive FromRow to specify the Rust type",
1292 note = "raw SQL and JSON expressions require explicit type annotation"
1293)]
1294pub trait ExprValueType {
1295 type ValueType;
1296}
1297
1298impl<V: crate::SQLParam, T, N, A> ExprValueType for crate::expr::SQLExpr<'_, V, T, N, A>
1299where
1300 T: crate::types::DataType + SQLTypeToRust<V::DialectMarker>,
1301 N: crate::expr::Nullability + WrapNullable<<T as SQLTypeToRust<V::DialectMarker>>::RustType>,
1302 A: crate::expr::AggregateKind,
1303{
1304 type ValueType = <N as WrapNullable<<T as SQLTypeToRust<V::DialectMarker>>::RustType>>::Output;
1305}
1306
1307impl<V: crate::SQLParam> ExprValueType for crate::sql::SQL<'_, V> {
1309 type ValueType = ();
1310}
1311
1312#[diagnostic::on_unimplemented(
1320 message = "`{Self}` is not a drizzle table",
1321 label = "ensure this type was derived with #[SQLiteTable] or #[PostgresTable]"
1322)]
1323pub trait HasSelectModel {
1324 type SelectModel;
1325 const COLUMN_COUNT: usize;
1326}
1327
1328#[diagnostic::on_unimplemented(
1335 message = "cannot resolve return type for this query",
1336 label = "the selected columns and table do not produce a known row type"
1337)]
1338pub trait ResolveRow<Table> {
1339 type Row;
1340}
1341
1342impl<T: HasSelectModel> ResolveRow<T> for SelectStar {
1343 type Row = T::SelectModel;
1344}
1345
1346impl<T> ResolveRow<T> for SelectExpr {
1347 type Row = ();
1348}
1349
1350impl<R, T> ResolveRow<T> for SelectAs<R>
1351where
1352 R: SelectAsFrom<T>,
1353{
1354 type Row = R;
1355}
1356
1357impl<M, Scope, T> ResolveRow<T> for Scoped<M, Scope>
1358where
1359 M: ResolveRow<T>,
1360{
1361 type Row = M::Row;
1362}
1363
1364#[diagnostic::on_unimplemented(
1369 message = "row selector `{Self}` cannot be used with table `{Table}`",
1370 label = "the #[from(...)] table does not match .from(...)",
1371 note = "set #[from(TheTable)] to the same table passed to .from(...)"
1372)]
1373pub trait SelectAsFrom<Table> {}
1374
1375macro_rules! impl_resolve_row_cols {
1378 ($($T:ident),+; $($idx:tt),+) => {
1379 impl<__Table, $($T: ExprValueType),+> ResolveRow<__Table> for SelectCols<($($T,)+)> {
1380 type Row = ($(<$T as ExprValueType>::ValueType,)+);
1381 }
1382 };
1383}
1384
1385with_col_sizes_8!(impl_resolve_row_cols);
1386
1387#[cfg(any(
1388 feature = "col16",
1389 feature = "col32",
1390 feature = "col64",
1391 feature = "col128",
1392 feature = "col200"
1393))]
1394with_col_sizes_16!(impl_resolve_row_cols);
1395
1396#[cfg(any(
1397 feature = "col32",
1398 feature = "col64",
1399 feature = "col128",
1400 feature = "col200"
1401))]
1402with_col_sizes_32!(impl_resolve_row_cols);
1403
1404#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
1405with_col_sizes_64!(impl_resolve_row_cols);
1406
1407#[cfg(any(feature = "col128", feature = "col200"))]
1408with_col_sizes_128!(impl_resolve_row_cols);
1409
1410#[cfg(feature = "col200")]
1411with_col_sizes_200!(impl_resolve_row_cols);
1412
1413macro_rules! selected_columns_cons {
1414 () => {
1415 crate::Nil
1416 };
1417 ($head:ident $(, $tail:ident)*) => {
1418 crate::Cons<<$head as ExprValueType>::ValueType, selected_columns_cons!($($tail),*)>
1419 };
1420}
1421
1422macro_rules! impl_selected_column_list_tuple {
1423 ($($T:ident),+; $($idx:tt),+) => {
1424 impl<$($T: ExprValueType),+> SelectedColumnList for ($($T,)+) {
1425 type Columns = selected_columns_cons!($($T),+);
1426 }
1427 };
1428}
1429
1430with_col_sizes_8!(impl_selected_column_list_tuple);
1431
1432#[cfg(any(
1433 feature = "col16",
1434 feature = "col32",
1435 feature = "col64",
1436 feature = "col128",
1437 feature = "col200"
1438))]
1439with_col_sizes_16!(impl_selected_column_list_tuple);
1440
1441#[cfg(any(
1442 feature = "col32",
1443 feature = "col64",
1444 feature = "col128",
1445 feature = "col200"
1446))]
1447with_col_sizes_32!(impl_selected_column_list_tuple);
1448
1449#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
1450with_col_sizes_64!(impl_selected_column_list_tuple);
1451
1452#[cfg(any(feature = "col128", feature = "col200"))]
1453with_col_sizes_128!(impl_selected_column_list_tuple);
1454
1455#[cfg(feature = "col200")]
1456with_col_sizes_200!(impl_selected_column_list_tuple);
1457
1458pub trait AfterJoin<CurrentRow, JoinedTable> {
1464 type NewRow;
1465}
1466
1467pub trait AfterLeftJoin<CurrentRow, JoinedTable> {
1469 type NewRow;
1470}
1471
1472pub trait AfterRightJoin<CurrentRow, JoinedTable> {
1474 type NewRow;
1475}
1476
1477pub trait AfterFullJoin<CurrentRow, JoinedTable> {
1479 type NewRow;
1480}
1481
1482impl<R, T: HasSelectModel> AfterJoin<R, T> for SelectStar {
1484 type NewRow = (R, T::SelectModel);
1485}
1486
1487impl<R, T: HasSelectModel> AfterLeftJoin<R, T> for SelectStar {
1489 type NewRow = (R, Option<T::SelectModel>);
1490}
1491
1492impl<R, T: HasSelectModel> AfterRightJoin<R, T> for SelectStar {
1494 type NewRow = (Option<R>, T::SelectModel);
1495}
1496
1497impl<R, T: HasSelectModel> AfterFullJoin<R, T> for SelectStar {
1499 type NewRow = (Option<R>, Option<T::SelectModel>);
1500}
1501
1502impl<Cols, R, T> AfterJoin<R, T> for SelectCols<Cols> {
1504 type NewRow = R;
1505}
1506
1507impl<Cols, R, T> AfterLeftJoin<R, T> for SelectCols<Cols> {
1508 type NewRow = R;
1509}
1510
1511impl<Cols, R, T> AfterRightJoin<R, T> for SelectCols<Cols> {
1512 type NewRow = R;
1513}
1514
1515impl<Cols, R, T> AfterFullJoin<R, T> for SelectCols<Cols> {
1516 type NewRow = R;
1517}
1518
1519impl<R, T> AfterJoin<R, T> for SelectExpr {
1521 type NewRow = R;
1522}
1523
1524impl<R, T> AfterLeftJoin<R, T> for SelectExpr {
1525 type NewRow = R;
1526}
1527
1528impl<R, T> AfterRightJoin<R, T> for SelectExpr {
1529 type NewRow = R;
1530}
1531
1532impl<R, T> AfterFullJoin<R, T> for SelectExpr {
1533 type NewRow = R;
1534}
1535
1536impl<Row, R, T> AfterJoin<R, T> for SelectAs<Row> {
1538 type NewRow = R;
1539}
1540
1541impl<Row, R, T> AfterLeftJoin<R, T> for SelectAs<Row> {
1542 type NewRow = R;
1543}
1544
1545impl<Row, R, T> AfterRightJoin<R, T> for SelectAs<Row> {
1546 type NewRow = R;
1547}
1548
1549impl<Row, R, T> AfterFullJoin<R, T> for SelectAs<Row> {
1550 type NewRow = R;
1551}
1552
1553impl<M, Scope, R, T> AfterJoin<R, T> for Scoped<M, Scope>
1554where
1555 M: AfterJoin<R, T>,
1556{
1557 type NewRow = M::NewRow;
1558}
1559
1560impl<M, Scope, R, T> AfterLeftJoin<R, T> for Scoped<M, Scope>
1561where
1562 M: AfterLeftJoin<R, T>,
1563{
1564 type NewRow = M::NewRow;
1565}
1566
1567impl<M, Scope, R, T> AfterRightJoin<R, T> for Scoped<M, Scope>
1568where
1569 M: AfterRightJoin<R, T>,
1570{
1571 type NewRow = M::NewRow;
1572}
1573
1574impl<M, Scope, R, T> AfterFullJoin<R, T> for Scoped<M, Scope>
1575where
1576 M: AfterFullJoin<R, T>,
1577{
1578 type NewRow = M::NewRow;
1579}
1580
1581#[diagnostic::on_unimplemented(
1600 message = "`{Self}` cannot be used as a select target",
1601 label = "this type does not implement IntoSelectTarget",
1602 note = "implement IntoSelectTarget or use a column, table, or typed expression"
1603)]
1604pub trait IntoSelectTarget {
1605 type Marker;
1606}
1607
1608impl IntoSelectTarget for () {
1610 type Marker = SelectStar;
1611}
1612
1613impl<V: crate::SQLParam> IntoSelectTarget for crate::sql::SQL<'_, V> {
1615 type Marker = SelectExpr;
1616}
1617
1618impl<V: crate::SQLParam, T, N, A> IntoSelectTarget for crate::expr::SQLExpr<'_, V, T, N, A>
1620where
1621 T: crate::types::DataType,
1622 N: crate::expr::Nullability,
1623 A: crate::expr::AggregateKind,
1624{
1625 type Marker = SelectCols<(Self,)>;
1626}
1627
1628macro_rules! impl_into_select_target_tuple {
1630 ($($T:ident),+; $($idx:tt),+) => {
1631 impl<$($T),+> IntoSelectTarget for ($($T,)+) {
1632 type Marker = SelectCols<($($T,)+)>;
1633 }
1634 };
1635}
1636
1637with_col_sizes_8!(impl_into_select_target_tuple);
1638
1639#[cfg(any(
1640 feature = "col16",
1641 feature = "col32",
1642 feature = "col64",
1643 feature = "col128",
1644 feature = "col200"
1645))]
1646with_col_sizes_16!(impl_into_select_target_tuple);
1647
1648#[cfg(any(
1649 feature = "col32",
1650 feature = "col64",
1651 feature = "col128",
1652 feature = "col200"
1653))]
1654with_col_sizes_32!(impl_into_select_target_tuple);
1655
1656#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
1657with_col_sizes_64!(impl_into_select_target_tuple);
1658
1659#[cfg(any(feature = "col128", feature = "col200"))]
1660with_col_sizes_128!(impl_into_select_target_tuple);
1661
1662#[cfg(feature = "col200")]
1663with_col_sizes_200!(impl_into_select_target_tuple);