ormer 0.1.8

An ORM framework with a usage style similar to Linq, supporting Sqlite, PostgresQL, MySQL
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
/// 宏定义 - 用于减少重复代码
///
/// 本文件包含用于生成重复代码模式的宏
/// 为 JOIN Executor 生成通用的 filter/range 方法
#[macro_export]
macro_rules! impl_join_executor_methods {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty
    ) => {
        impl<T: $crate::Model, J: $crate::Model> $executor_type<T, J> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为 CollectFuture 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_collect_future {
    (
        $future_type:ident,
        $output_type:ty,
        lifetime: $($lt:lifetime),*
    ) => {
        impl<$($lt,)* T: $crate::Model + 'static, J: $crate::Model + 'static>
            std::future::IntoFuture for $future_type<$($lt,)* T, J>
        {
            type Output = $output_type;
            type IntoFuture = std::pin::Pin<
                Box<dyn std::future::Future<Output = Self::Output> + $($lt +)* 'static>
            >;

            fn into_future(self) -> Self::IntoFuture {
                Box::pin(async move { self.executor.collect_inner().await })
            }
        }
    };
}

/// 为 CollectFuture (单表) 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_single_collect_future {
    (
        $future_type:ident,
        $output_type:ty,
        lifetime: $($lt:lifetime),*
    ) => {
        impl<$($lt,)* T: $crate::Model + 'static, C: FromIterator<T> + 'static>
            std::future::IntoFuture for $future_type<$($lt,)* T, C>
        {
            type Output = $output_type;
            type IntoFuture = std::pin::Pin<
                Box<dyn std::future::Future<Output = Self::Output> + $($lt +)* 'static>
            >;

            fn into_future(self) -> Self::IntoFuture {
                Box::pin(async move { self.executor.collect_inner().await })
            }
        }
    };
}

/// 为 Executor 生成通用的方法 (filter/order_by/range)
#[macro_export]
macro_rules! impl_executor_methods {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty
    ) => {
        impl<'a, T: $crate::Model> $executor_type<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by_desc<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by_desc(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为统一的 SelectExecutor 生成方法(filter/order_by/range)
#[macro_export]
macro_rules! impl_unified_select_executor_methods {
    ($executor_name:ident) => {
        impl<'a, T: $crate::Model> $executor_name<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec) => $executor_name::Sqlite(exec.filter(f)),
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => $executor_name::PostgreSQL(exec.filter(f)),
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.filter(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("SelectExecutor not implemented for this backend"),
                }
            }

            pub fn order_by<F, O>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec) => $executor_name::Sqlite(exec.order_by(f)),
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.order_by(f))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.order_by(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("SelectExecutor not implemented for this backend"),
                }
            }

            pub fn order_by_desc<F, O>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec) => $executor_name::Sqlite(exec.order_by_desc(f)),
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.order_by_desc(f))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.order_by_desc(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("SelectExecutor not implemented for this backend"),
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec) => $executor_name::Sqlite(exec.range(range)),
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.range(range))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.range(range)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("SelectExecutor not implemented for this backend"),
                }
            }
        }
    };
}

/// 为统一的 DeleteExecutor 生成方法
#[macro_export]
macro_rules! impl_unified_delete_executor {
    ($executor_name:ident) => {
        impl<'a, T: $crate::Model> $executor_name<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.filter(f), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => $executor_name::PostgreSQL(exec.filter(f)),
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.filter(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("DeleteExecutor not implemented for this backend"),
                }
            }

            pub async fn execute(self) -> anyhow::Result<u64> {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, _) => exec.execute().await,
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => exec.execute().await,
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => exec.execute().await,
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("DeleteExecutor not implemented for this backend"),
                }
            }
        }

        impl<'a, T: $crate::Model + 'static> std::future::IntoFuture for $executor_name<'a, T> {
            type Output = anyhow::Result<u64>;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                Box::pin(async move { self.execute().await })
            }
        }
    };
}

/// 为统一的 UpdateExecutor 生成方法
#[macro_export]
macro_rules! impl_unified_update_executor {
    ($executor_name:ident) => {
        impl<'a, T: $crate::Model> $executor_name<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.filter(f), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => $executor_name::PostgreSQL(exec.filter(f)),
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.filter(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("UpdateExecutor not implemented for this backend"),
                }
            }

            pub fn set<F, V, C>(self, field_fn: F, value: V) -> Self
            where
                F: FnOnce(T::Where) -> $crate::query::builder::TypedColumn<C>,
                V: Into<$crate::model::Value>,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.set(field_fn, value), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.set(field_fn, value))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.set(field_fn, value)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("UpdateExecutor not implemented for this backend"),
                }
            }

            pub async fn execute(self) -> anyhow::Result<u64> {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, _) => exec.execute().await,
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => exec.execute().await,
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => exec.execute().await,
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("UpdateExecutor not implemented for this backend"),
                }
            }
        }

        impl<'a, T: $crate::Model + 'static> std::future::IntoFuture for $executor_name<'a, T> {
            type Output = anyhow::Result<u64>;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                Box::pin(async move { self.execute().await })
            }
        }
    };
}

/// 为统一的 CollectFuture 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_unified_collect_future {
    ($future_name:ident) => {
        impl<'a, T: $crate::Model + 'static, C: FromIterator<T> + 'static> std::future::IntoFuture
            for $future_name<'a, T, C>
        {
            type Output = anyhow::Result<C>;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                match self {
                    #[cfg(feature = "sqlite")]
                    $future_name::Sqlite(future) => Box::pin(future.into_future()),
                    #[cfg(feature = "postgresql")]
                    $future_name::PostgreSQL(future) => Box::pin(future.into_future()),
                    #[cfg(feature = "mysql")]
                    $future_name::MySQL(future) => Box::pin(future.into_future()),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("CollectFuture not implemented for this backend"),
                }
            }
        }
    };
}

/// 为统一的 AggregateFuture 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_unified_aggregate_future {
    ($future_name:ident) => {
        impl<'a, T: $crate::Model + 'static, R: $crate::model::FromValue + 'static>
            std::future::IntoFuture for $future_name<'a, T, R>
        {
            type Output = anyhow::Result<R>;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                match self {
                    #[cfg(feature = "sqlite")]
                    $future_name::Sqlite(future, _) => Box::pin(async move { future.await }),
                    #[cfg(feature = "postgresql")]
                    $future_name::PostgreSQL(future) => Box::pin(async move { future.await }),
                    #[cfg(feature = "mysql")]
                    $future_name::MySQL(future) => Box::pin(async move { future.await }),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("AggregateFuture not implemented for this backend"),
                }
            }
        }
    };
}

/// 为统一的 JOIN Executor 生成 filter/range 方法
#[macro_export]
macro_rules! impl_unified_join_executor {
    ($executor_name:ident) => {
        impl<'a, T: $crate::Model, J: $crate::Model> $executor_name<'a, T, J> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.filter(f), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => $executor_name::PostgreSQL(exec.filter(f)),
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.filter(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("JoinExecutor not implemented for this backend"),
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.range(range), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.range(range))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.range(range)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("JoinExecutor not implemented for this backend"),
                }
            }
        }
    };
}

/// 为统一的 JOIN CollectFuture 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_unified_join_collect_future {
    ($future_name:ident, $output_type:ty) => {
        impl<'a, T: $crate::Model + 'static, J: $crate::Model + 'static> std::future::IntoFuture
            for $future_name<'a, T, J>
        {
            type Output = $output_type;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                match self {
                    #[cfg(feature = "sqlite")]
                    $future_name::Sqlite(future, _) => Box::pin(future.into_future()),
                    #[cfg(feature = "postgresql")]
                    $future_name::PostgreSQL(future) => Box::pin(future.into_future()),
                    #[cfg(feature = "mysql")]
                    $future_name::MySQL(future) => Box::pin(future.into_future()),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("JoinCollectFuture not implemented for this backend"),
                }
            }
        }
    };
}

/// 为统一的 RelatedSelectExecutor 生成方法
#[macro_export]
macro_rules! impl_unified_related_select_executor {
    ($executor_name:ident) => {
        impl<'a, T: $crate::Model, R: $crate::Model> $executor_name<'a, T, R> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where, R::Where) -> $crate::WhereExpr,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.filter(f), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => $executor_name::PostgreSQL(exec.filter(f)),
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.filter(f)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("RelatedSelectExecutor not implemented for this backend"),
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        $executor_name::Sqlite(exec.range(range), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        $executor_name::PostgreSQL(exec.range(range))
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => $executor_name::MySQL(exec.range(range)),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("RelatedSelectExecutor not implemented for this backend"),
                }
            }

            pub fn collect<C: FromIterator<T> + 'static>(self) -> RelatedCollectFuture<'a, T, R>
            where
                T: 'static,
                R: 'static,
            {
                match self {
                    #[cfg(feature = "sqlite")]
                    $executor_name::Sqlite(exec, phantom) => {
                        RelatedCollectFuture::Sqlite(exec.exec(), phantom)
                    }
                    #[cfg(feature = "postgresql")]
                    $executor_name::PostgreSQL(exec) => {
                        RelatedCollectFuture::PostgreSQL(exec.exec())
                    }
                    #[cfg(feature = "mysql")]
                    $executor_name::MySQL(exec) => RelatedCollectFuture::MySQL(exec.exec()),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("RelatedSelectExecutor not implemented for this backend"),
                }
            }

            pub fn exec(self) -> RelatedCollectFuture<'a, T, R>
            where
                T: 'static,
                R: 'static,
            {
                self.collect::<Vec<T>>()
            }

            pub fn execute(self) -> RelatedCollectFuture<'a, T, R>
            where
                T: 'static,
                R: 'static,
            {
                self.collect::<Vec<T>>()
            }
        }
    };
}

/// 为统一的 RelatedCollectFuture 生成 IntoFuture 实现
#[macro_export]
macro_rules! impl_unified_related_collect_future {
    ($future_name:ident) => {
        impl<'a, T: $crate::Model + 'static, R: $crate::Model + 'static> std::future::IntoFuture
            for $future_name<'a, T, R>
        {
            type Output = anyhow::Result<Vec<T>>;
            type IntoFuture =
                std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + 'a>>;

            fn into_future(self) -> Self::IntoFuture {
                match self {
                    #[cfg(feature = "sqlite")]
                    $future_name::Sqlite(future, _) => Box::pin(future.into_future()),
                    #[cfg(feature = "postgresql")]
                    $future_name::PostgreSQL(future) => Box::pin(future.into_future()),
                    #[cfg(feature = "mysql")]
                    $future_name::MySQL(future) => Box::pin(future.into_future()),
                    #[allow(unreachable_patterns)]
                    _ => unreachable!("RelatedCollectFuture not implemented for this backend"),
                }
            }
        }
    };
}

/// 为数据库后端的 Executor 生成通用的 filter/order_by/range 方法
/// 这个宏用于消除三个后端中重复的 Executor 方法实现
#[macro_export]
macro_rules! impl_backend_executor_methods {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<'a, T: $crate::Model> $executor_type<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by_desc<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by_desc(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为数据库后端的 JOIN Executor 生成通用的 filter/range 方法
#[macro_export]
macro_rules! impl_backend_join_executor_methods {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<T: $crate::Model, J: $crate::Model> $executor_type<T, J> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为数据库后端的 RelatedSelectExecutor 生成通用方法
#[macro_export]
macro_rules! impl_backend_related_executor_methods {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<T: $crate::Model, R: $crate::Model> $executor_type<T, R> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where, R::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为带有生命周期参数的数据库后端 Executor 生成通用的 filter/order_by/range 方法
#[macro_export]
macro_rules! impl_backend_executor_methods_with_lifetime {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<'a, T: $crate::Model> $executor_type<'a, T> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn order_by_desc<F, O>(self, f: F) -> Self
            where
                F: FnOnce(<T as $crate::Model>::Where) -> O,
                O: Into<$crate::OrderBy>,
            {
                Self {
                    select: self.select.order_by_desc(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为带有生命周期参数的数据库后端 JOIN Executor 生成通用的 filter/range 方法
#[macro_export]
macro_rules! impl_backend_join_executor_methods_with_lifetime {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<'a, T: $crate::Model, J: $crate::Model> $executor_type<'a, T, J> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 为带有生命周期参数的数据库后端 RelatedSelectExecutor 生成通用方法
#[macro_export]
macro_rules! impl_backend_related_executor_methods_with_lifetime {
    (
        $executor_type:ident,
        $conn_field:ident,
        $conn_type:ty,
        $select_type:ident
    ) => {
        impl<'a, T: $crate::Model, R: $crate::Model> $executor_type<'a, T, R> {
            pub fn filter<F>(self, f: F) -> Self
            where
                F: FnOnce(T::Where, R::Where) -> $crate::WhereExpr,
            {
                Self {
                    select: self.select.filter(f),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }

            pub fn range<RR: Into<$crate::query::builder::RangeBounds>>(self, range: RR) -> Self {
                Self {
                    select: self.select.range(range),
                    $conn_field: self.$conn_field,
                    _marker: std::marker::PhantomData,
                }
            }
        }
    };
}

/// 示例用法 (在实际代码中使用):
///
/// ```ignore
/// // 在 sqlite_backend.rs 中:
/// ormer::impl_join_executor_methods!(LeftJoinedSelectExecutor, conn, Arc<Sqlite::Connection>);
/// ormer::impl_join_executor_methods!(InnerJoinedSelectExecutor, conn, Arc<Sqlite::Connection>);
/// ormer::impl_join_executor_methods!(RightJoinedSelectExecutor, conn, Arc<Sqlite::Connection>);
///
/// // 在 mysql_backend.rs 中:
/// ormer::impl_join_executor_methods!(LeftJoinedSelectExecutor, pool, &'a Pool);
/// ormer::impl_join_executor_methods!(InnerJoinedSelectExecutor, pool, &'a Pool);
/// ormer::impl_join_executor_methods!(RightJoinedSelectExecutor, pool, &'a Pool);
/// ```
///
pub fn _placeholder() {}