1use std::future::Future;
33
34use crate::context::Params;
35use crate::db::{Changeset, Expr, Order, Preload, Query, Record, Row, Save, ToValue, Value};
36use crate::error::Result;
37
38pub trait Callbacks: Send {
76 fn validate_record(&self, errors: &mut crate::db::Errors) {
80 let _ = errors;
81 }
82
83 fn before_validation(&mut self) -> impl Future<Output = Result<()>> + Send {
84 async { Ok(()) }
85 }
86 fn before_save(&mut self) -> impl Future<Output = Result<()>> + Send {
87 async { Ok(()) }
88 }
89 fn before_create(&mut self) -> impl Future<Output = Result<()>> + Send {
90 async { Ok(()) }
91 }
92 fn before_update(&mut self) -> impl Future<Output = Result<()>> + Send {
93 async { Ok(()) }
94 }
95 fn after_create(&mut self) -> impl Future<Output = Result<()>> + Send {
96 async { Ok(()) }
97 }
98 fn after_update(&mut self) -> impl Future<Output = Result<()>> + Send {
99 async { Ok(()) }
100 }
101 fn after_save(&mut self) -> impl Future<Output = Result<()>> + Send {
102 async { Ok(()) }
103 }
104 fn before_destroy(&mut self) -> impl Future<Output = Result<()>> + Send {
105 async { Ok(()) }
106 }
107 fn after_destroy(&mut self) -> impl Future<Output = Result<()>> + Send {
108 async { Ok(()) }
109 }
110}
111
112pub trait Model: Callbacks + Sized + Send + Sync + 'static {
113 const TABLE: &'static str;
115 const COLUMNS: &'static [&'static str];
116 const ATTRIBUTES: &'static [&'static str] = Self::COLUMNS;
120 const OWNER: &'static [(&'static str, &'static str)] = &[];
125 const PARENTS: &'static [Parent] = &[];
128 const ENCRYPTED: &'static [&'static str] = &[];
131 const GLOBAL_ROWS: bool = false;
135 const SOFT_DELETE: Option<&'static str> = None;
140 const DETERMINISTIC: &'static [&'static str] = &[];
143 const HIDDEN: &'static [&'static str] = &[];
147 const PRIMARY_KEY: &'static str = "id";
148 const INTEGER_KEY: bool = true;
151 const DATABASE: Option<&'static str> = None;
154 #[doc(hidden)]
157 const ATTACHMENTS: bool = false;
158 const CREATED_AT: Option<&'static str> = None;
161 const UPDATED_AT: Option<&'static str> = None;
163
164 type Columns;
166
167 fn columns() -> Self::Columns;
168 fn from_row(row: &Row) -> Result<Self>;
169 fn values(&self) -> Vec<(&'static str, Value)>;
171 #[doc(hidden)]
179 fn normalize_fields(&mut self) {}
180 #[doc(hidden)]
183 fn belongs_to_defaults(&mut self) -> impl Future<Output = Result<()>> + Send {
184 async { Ok(()) }
185 }
186 #[doc(hidden)]
189 fn validate_attributes(&self, errors: &mut crate::db::Errors) {
190 let _ = errors;
191 }
192 #[doc(hidden)]
193 fn set_value(&mut self, column: &str, value: Value) -> bool {
194 let _ = (column, value);
195 false
196 }
197 #[doc(hidden)]
200 fn blank() -> Option<Self> {
201 None
202 }
203 fn attribute_values(&self) -> Vec<(&'static str, Value)> {
205 Vec::new()
206 }
207 fn id_value(&self) -> Value;
208
209 fn validate(changeset: Changeset<Self>) -> Changeset<Self> {
212 changeset
213 }
214
215 fn from_params(params: &Params) -> Changeset<Self> {
219 let _ = params;
220 Changeset::new()
221 }
222
223 fn params_schema() -> serde_json::Value {
226 serde_json::json!({"type": "object"})
227 }
228
229 fn path(&self) -> String {
232 let id = self.id_value().to_text();
233 let values = self.values();
236 let collection = crate::router::collection_path_of(Self::TABLE, |param| {
237 values
238 .iter()
239 .find(|(column, _)| *column == param)
240 .map(|(_, value)| value.to_text())
241 });
242 format!("{collection}/{}", crate::router::encode_segment(&id))
243 }
244
245 fn collection_path() -> String {
247 crate::router::collection_path_of(Self::TABLE, |_| None)
248 }
249
250 fn all() -> Query<Self> {
252 Query::new()
253 }
254
255 fn default_scope(query: Query<Self>) -> Query<Self> {
258 query
259 }
260
261 fn r#for(access: &dyn crate::access::Access) -> Query<Self> {
266 Query::new().owned_by(access)
267 }
268
269 fn set_owner(&mut self, column: &str, value: &str) {
272 let _ = (column, value);
273 }
274
275 fn unscoped() -> Query<Self> {
277 Query::unscoped()
278 }
279
280 fn filter(condition: impl FnOnce(&Self::Columns) -> Expr) -> Query<Self> {
281 Query::new().filter(condition)
282 }
283
284 fn where_sql(sql: &str, values: impl IntoIterator<Item = crate::db::Value>) -> Query<Self> {
287 Self::all().where_sql(sql, values)
288 }
289
290 fn order(order: impl FnOnce(&Self::Columns) -> Order) -> Query<Self> {
291 Query::new().order(order)
292 }
293
294 fn preload<P: Into<Preload<Self>>>(
297 association: impl FnOnce(&Self::Columns) -> P,
298 ) -> Query<Self> {
299 Query::new().preload(association)
300 }
301
302 fn find(id: impl ToValue) -> impl Future<Output = Result<Self>> + Send {
307 let id = match id.to_value() {
308 crate::db::Value::Text(text) if Self::INTEGER_KEY => {
309 text.trim().parse::<i64>().map(crate::db::Value::Int).ok()
310 }
311 value => Some(value),
312 };
313 let query = id.map(by_id::<Self>);
314 async move {
315 match query {
316 Some(query) => query.one().await,
317 None => Err(crate::Error::not_found()),
318 }
319 }
320 }
321
322 fn find_by(
324 condition: impl FnOnce(&Self::Columns) -> Expr,
325 ) -> impl Future<Output = Result<Option<Self>>> + Send {
326 let query = Self::filter(condition);
327 async move { query.first().await }
328 }
329
330 fn find_or_initialize_by(
334 condition: impl FnOnce(&Self::Columns) -> Expr,
335 init: impl FnOnce(&mut Self) + Send,
336 ) -> impl Future<Output = Result<Self>> + Send
337 where
338 Self: Default,
339 {
340 let query = Self::filter(condition);
341 async move {
342 Ok(match query.first().await? {
343 Some(found) => found,
344 None => Self::default().tap(init),
345 })
346 }
347 }
348
349 fn find_or_create_by(
353 condition: impl FnOnce(&Self::Columns) -> Expr,
354 init: impl FnOnce(&mut Self) + Send,
355 ) -> impl Future<Output = Result<Self>> + Send
356 where
357 Self: Default + Clone,
358 {
359 let query = Self::filter(condition);
360 async move {
361 if let Some(found) = query.first().await? {
362 return Ok(found);
363 }
364 let mut record = Self::default().tap(init);
365 record.save().await?;
366 Ok(record)
367 }
368 }
369
370 fn first() -> impl Future<Output = Result<Option<Self>>> + Send {
372 Query::<Self>::new().first()
373 }
374
375 fn last() -> impl Future<Output = Result<Option<Self>>> + Send {
377 Query::<Self>::new().last()
378 }
379
380 fn take(n: u64) -> impl Future<Output = Result<Vec<Self>>> + Send {
382 Query::<Self>::new()
383 .order(|_| Order::by(Self::PRIMARY_KEY, false))
384 .take(n)
385 }
386
387 fn count() -> impl Future<Output = Result<i64>> + Send {
388 Query::<Self>::new().count()
389 }
390
391 fn ids() -> impl Future<Output = Result<Vec<i64>>> + Send {
393 Query::<Self>::new().ids()
394 }
395
396 fn exists() -> impl Future<Output = Result<bool>> + Send {
399 Query::<Self>::new().exists()
400 }
401
402 fn join<C: Model>(
405 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
406 condition: impl FnOnce(&C::Columns) -> Expr,
407 ) -> Query<Self> {
408 Query::new().join(association, condition)
409 }
410
411 fn joins<C: Model>(
413 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
414 ) -> Query<Self> {
415 Query::new().joins(association)
416 }
417
418 fn group<K: crate::db::FromColumn>(
421 column: impl FnOnce(&Self::Columns) -> crate::db::Col<Self, K>,
422 ) -> crate::db::Grouped<Self, K> {
423 Query::new().group(column)
424 }
425
426 fn sum<T: crate::db::Summable>(
428 column: impl FnOnce(&Self::Columns) -> crate::db::Col<Self, T>,
429 ) -> impl Future<Output = Result<T::Sum>> + Send {
430 Query::<Self>::new().sum(column)
431 }
432
433 fn average<T: crate::db::Summable>(
435 column: impl FnOnce(&Self::Columns) -> crate::db::Col<Self, T>,
436 ) -> impl Future<Output = Result<Option<f64>>> + Send {
437 Query::<Self>::new().average(column)
438 }
439
440 fn minimum<T: crate::db::Aggregable>(
442 column: impl FnOnce(&Self::Columns) -> crate::db::Col<Self, T>,
443 ) -> impl Future<Output = Result<Option<T::Value>>> + Send {
444 Query::<Self>::new().minimum(column)
445 }
446
447 fn maximum<T: crate::db::Aggregable>(
449 column: impl FnOnce(&Self::Columns) -> crate::db::Col<Self, T>,
450 ) -> impl Future<Output = Result<Option<T::Value>>> + Send {
451 Query::<Self>::new().maximum(column)
452 }
453
454 fn create(
467 changes: impl Into<Changeset<Self>>,
468 ) -> impl Future<Output = Result<Save<Self>>> + Send {
469 let changeset = changes.into();
470 async move { crate::db::record::write_changeset(changeset, true).await }
471 }
472
473 fn create_with(
478 change: impl FnOnce(&mut Self),
479 ) -> impl Future<Output = Result<Save<Self>>> + Send
480 where
481 Self: Default + Clone,
482 {
483 let mut record = Self::build_with(change);
484 async move {
485 if record.save().await? {
486 return Ok(Save::Saved(record));
487 }
488 let mut changeset = Changeset::<Self>::new();
489 for (column, message) in record.errors() {
490 changeset = changeset.push_error(column, message.clone());
491 }
492 Ok(Save::Invalid(changeset))
493 }
494 }
495
496 fn changeset() -> Changeset<Self> {
498 Changeset::new()
499 }
500
501 fn change(self) -> Changeset<Self> {
503 Changeset::for_record(self)
504 }
505
506 fn update_changeset(
513 self,
514 changes: impl Into<Changeset<Self>>,
515 ) -> impl Future<Output = Result<Save<Self>>> + Send {
516 let changeset = changes.into().attach(self);
517 async move { crate::db::record::write_changeset(changeset, false).await }
518 }
519
520 fn destroy(mut self) -> impl Future<Output = Result<()>> + Send {
523 async move {
524 self.check_not_shared()?;
525 self.before_destroy().await?;
526 if Self::SOFT_DELETE.is_none() {
528 self.destroy_dependents().await?;
529 }
530 by_id::<Self>(self.id_value())
531 .of_record()
532 .delete_all()
533 .await?;
534 for file in self.attached_files() {
535 file.remove().await?;
536 }
537 self.touch_parents().await?;
538 self.after_destroy().await
539 }
540 }
541
542 #[doc(hidden)]
546 fn take_attachments(&mut self) -> Vec<crate::attachment::Pending> {
547 Vec::new()
548 }
549
550 #[doc(hidden)]
552 fn attached_files(&self) -> Vec<crate::attachment::Attached> {
553 Vec::new()
554 }
555
556 #[doc(hidden)]
559 fn touch_parents(&self) -> impl Future<Output = Result<()>> + Send {
560 async { Ok(()) }
561 }
562
563 #[doc(hidden)]
566 fn destroy_dependents(&self) -> impl Future<Output = Result<()>> + Send {
567 async { Ok(()) }
568 }
569
570 fn delete(self) -> impl Future<Output = Result<()>> + Send {
572 let query = by_id::<Self>(self.id_value()).of_record();
573 let shared = self.check_not_shared();
574 async move {
575 shared?;
576 query.delete_all().await?;
577 Ok(())
578 }
579 }
580
581 fn is_trashed(&self) -> bool {
583 Self::SOFT_DELETE.is_some_and(|column| {
584 self.values()
585 .into_iter()
586 .any(|(c, value)| c == column && !value.is_null())
587 })
588 }
589
590 fn restore(&mut self) -> impl Future<Output = Result<()>> + Send {
593 let column = Self::SOFT_DELETE;
594 let query = by_id::<Self>(self.id_value()).of_record().with_trashed();
595 if let Some(column) = column {
596 self.set_value(column, Value::Null);
597 }
598 async move {
599 let Some(column) = column else {
600 return Err(crate::Error::internal(
601 "restore is for a model with `soft_deletes`",
602 ));
603 };
604 query
605 .update_all(|_| [crate::db::Assign::new(column, Value::Null)])
606 .await?;
607 Ok(())
608 }
609 }
610
611 fn force_delete(self) -> impl Future<Output = Result<()>> + Send {
613 let query = by_id::<Self>(self.id_value()).of_record().with_trashed();
614 let shared = self.check_not_shared();
615 async move {
616 shared?;
617 query.force_delete_all().await?;
618 Ok(())
619 }
620 }
621
622 fn where_has<C: Model>(
625 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
626 inner: impl FnOnce(Query<C>) -> Query<C>,
627 ) -> Query<Self> {
628 Query::new().where_has(association, inner)
629 }
630
631 fn without<C: Model>(
633 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
634 ) -> Query<Self> {
635 Query::new().without(association)
636 }
637
638 fn with_trashed() -> Query<Self> {
640 Query::new().with_trashed()
641 }
642
643 fn only_trashed() -> Query<Self> {
645 Query::new().only_trashed()
646 }
647
648 #[doc(hidden)]
651 fn check_not_shared(&self) -> Result<()> {
652 if !Self::GLOBAL_ROWS || crate::access::may_change_shared() {
653 return Ok(());
654 }
655 let values = self.values();
656 let shared = Self::OWNER.iter().all(|(column, _)| {
657 values
658 .iter()
659 .find(|(c, _)| c == column)
660 .is_none_or(|(_, value)| value.is_null())
661 });
662 if shared {
663 Err(crate::Error::new(
664 http::StatusCode::FORBIDDEN,
665 "a shared row changes only `unscoped`",
666 ))
667 } else {
668 Ok(())
669 }
670 }
671
672 fn touch(&self) -> impl Future<Output = Result<()>> + Send {
676 crate::db::assoc::touch_parent::<Self>(self.id_value())
677 }
678
679 fn record(&self) -> Option<&Record> {
684 None
685 }
686
687 fn record_mut(&mut self) -> Option<&mut Record> {
688 None
689 }
690
691 fn new() -> Self
693 where
694 Self: Default,
695 {
696 Self::default()
697 }
698
699 fn tap(mut self, change: impl FnOnce(&mut Self)) -> Self {
702 change(&mut self);
703 self
704 }
705
706 fn build(params: impl Into<Params>) -> Self
708 where
709 Self: Default,
710 {
711 let mut record = Self::default();
712 record.assign(¶ms.into());
713 record
714 }
715
716 fn build_with(change: impl FnOnce(&mut Self)) -> Self
719 where
720 Self: Default,
721 {
722 let mut record = Self::default();
723 change(&mut record);
724 record
725 }
726
727 fn load<P: Into<crate::db::Preload<Self>>>(
730 &mut self,
731 association: impl FnOnce(&Self::Columns) -> P,
732 ) -> impl Future<Output = Result<()>> + Send {
733 let preload = association(&Self::columns()).into();
734 async move {
735 let conn = crate::db::current_in(Self::DATABASE)?;
736 preload.run(std::slice::from_mut(self), conn).await
737 }
738 }
739
740 fn build_in<C: Model + Default>(
744 &self,
745 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
746 change: impl FnOnce(&mut C),
747 ) -> C {
748 let association = association(&Self::columns());
749 let (own, other) = association
750 .join
751 .expect("build_in is for a `has_many` (not `through` a join table)");
752 let key = self
753 .values()
754 .into_iter()
755 .find(|(column, _)| *column == own)
756 .map_or(Value::Null, |(_, value)| value);
757 let mut child = C::default();
758 change(&mut child);
759 child.set_value(other, key);
760 if let Some((column, name)) = association.kind {
762 child.set_value(column, Value::Text(name.to_owned()));
763 }
764 child
765 }
766
767 fn attach<C: Model>(
771 &self,
772 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
773 ids: impl IntoIterator<Item = i64>,
774 ) -> impl Future<Output = Result<()>> + Send {
775 self.write_links(association, ids, crate::db::assoc::Links::Add)
776 }
777
778 fn detach<C: Model>(
780 &self,
781 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
782 ids: impl IntoIterator<Item = i64>,
783 ) -> impl Future<Output = Result<()>> + Send {
784 self.write_links(association, ids, crate::db::assoc::Links::Remove)
785 }
786
787 fn sync<C: Model>(
790 &self,
791 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
792 ids: impl IntoIterator<Item = i64>,
793 ) -> impl Future<Output = Result<()>> + Send {
794 self.write_links(association, ids, crate::db::assoc::Links::Exactly)
795 }
796
797 #[doc(hidden)]
798 fn write_links<C: Model>(
799 &self,
800 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
801 ids: impl IntoIterator<Item = i64>,
802 links: crate::db::assoc::Links,
803 ) -> impl Future<Output = Result<()>> + Send {
804 let through = association(&Self::columns()).through;
805 let owner = self.id_value();
806 let ids: Vec<i64> = ids.into_iter().collect();
807 async move {
808 let (table, owner_key, target_key) = through.ok_or_else(|| {
809 crate::Error::internal("attach, detach and sync are for a `has_many … through:`")
810 })?;
811 crate::db::assoc::write_through_ids(owner, table, owner_key, target_key, ids, links)
812 .await
813 }
814 }
815
816 fn create_in<C: Model + Default + Clone>(
818 &self,
819 association: impl FnOnce(&Self::Columns) -> crate::db::Association<Self, C>,
820 change: impl FnOnce(&mut C),
821 ) -> impl Future<Output = Result<crate::db::Save<C>>> + Send {
822 let mut child = self.build_in(association, change);
823 async move {
824 if child.save().await? {
825 return Ok(crate::db::Save::Saved(child));
826 }
827 let mut changeset = crate::db::Changeset::<C>::new();
828 for (column, message) in child.errors() {
829 changeset = changeset.push_error(column, message.clone());
830 }
831 Ok(crate::db::Save::Invalid(changeset))
832 }
833 }
834
835 fn assign(&mut self, params: &Params) {
838 let _ = params;
839 }
840
841 #[doc(hidden)]
844 fn assign_protected(&mut self, params: &Params) {
845 let _ = params;
846 }
847
848 fn is_new(&self) -> bool {
850 match self.record() {
851 Some(state) => !state.is_persisted(),
852 None => matches!(self.id_value(), Value::Null | Value::Int(0)),
853 }
854 }
855
856 fn is_persisted(&self) -> bool {
857 !self.is_new()
858 }
859
860 fn changes(&self) -> Vec<(&'static str, Value)> {
863 crate::db::record::changes(self)
864 }
865
866 fn is_changed(&self) -> bool {
867 !self.changes().is_empty()
868 }
869
870 fn changed(&self, column: &str) -> bool {
872 self.changes().iter().any(|(c, _)| *c == column)
873 }
874
875 fn was(&self, column: &str) -> Option<Value> {
877 self.record()?.original(column).cloned()
878 }
879
880 fn save(&mut self) -> impl Future<Output = Result<bool>> + Send
883 where
884 Self: Clone,
885 {
886 crate::db::record::save(self)
887 }
888
889 fn update(&mut self, params: impl Into<Params>) -> impl Future<Output = Result<bool>> + Send
896 where
897 Self: Clone,
898 {
899 let params = params.into();
900 self.assign(¶ms);
901 async move {
902 if !Self::HAS_NESTED {
903 return crate::db::record::save(self).await;
904 }
905 let state = self.record().cloned();
908 let kept: Vec<(&'static str, Value)> = self
909 .values()
910 .into_iter()
911 .filter(|(column, _)| {
912 *column == Self::PRIMARY_KEY
913 || Some(*column) == Self::CREATED_AT
914 || Some(*column) == Self::UPDATED_AT
915 })
916 .collect();
917 let saved = crate::db::savepoint_in(Self::DATABASE, async {
918 if !crate::db::record::save(&mut *self).await? || !self.save_nested(¶ms).await?
919 {
920 return Err(crate::db::assoc::nested_invalid());
921 }
922 Ok(())
923 })
924 .await;
925 if saved.is_err() {
926 for (column, value) in kept {
930 self.set_value(column, value);
931 }
932 if let (Some(state), Some(now)) = (state, self.record_mut()) {
933 let errors = now.errors().to_vec();
934 *now = state;
935 now.set_errors(errors);
936 }
937 }
938 match saved {
939 Ok(()) => Ok(true),
940 Err(err) if crate::db::assoc::is_nested_invalid(&err) => Ok(false),
941 Err(err) => Err(err),
942 }
943 }
944 }
945
946 #[doc(hidden)]
948 const HAS_NESTED: bool = false;
949
950 #[doc(hidden)]
954 fn save_nested<'a>(
955 &'a mut self,
956 params: &'a Params,
957 ) -> std::pin::Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>> {
958 let _ = params;
959 Box::pin(async { Ok(true) })
960 }
961
962 fn update_with(
965 &mut self,
966 change: impl FnOnce(&mut Self),
967 ) -> impl Future<Output = Result<bool>> + Send
968 where
969 Self: Clone,
970 {
971 change(self);
972 crate::db::record::save(self)
973 }
974
975 fn reload(&mut self) -> impl Future<Output = Result<()>> + Send {
977 let query = by_id::<Self>(self.id_value()).of_record();
978 async move {
979 *self = query.one().await?;
980 Ok(())
981 }
982 }
983
984 fn errors(&self) -> &[(&'static str, String)] {
986 self.record().map_or(&[], Record::errors)
987 }
988
989 fn errors_on(&self, column: &str) -> Vec<&str> {
991 self.errors()
992 .iter()
993 .filter(|(c, _)| *c == column)
994 .map(|(_, m)| m.as_str())
995 .collect()
996 }
997
998 fn errors_json(&self) -> serde_json::Value {
1000 crate::db::record::errors_json(self.errors())
1001 }
1002
1003 fn messages(&self) -> Vec<String> {
1006 self.errors()
1007 .iter()
1008 .map(|(c, m)| format!("{} {m}", c.replace('_', " ")))
1009 .collect()
1010 }
1011
1012 fn full_messages(&self) -> Vec<String> {
1015 self.errors()
1016 .iter()
1017 .map(|(c, m)| format!("{} {m}", crate::db::humanize(c)))
1018 .collect()
1019 }
1020
1021 fn field(&self, column: &str) -> crate::view::Field {
1024 crate::view::Field::new(
1025 column,
1026 self.text(column),
1027 self.errors_on(column)
1028 .into_iter()
1029 .map(str::to_owned)
1030 .collect(),
1031 )
1032 }
1033
1034 fn text(&self, column: &str) -> String {
1037 if let Some(raw) = self.record().and_then(|r| r.raw(column)) {
1038 return raw.to_owned();
1039 }
1040 self.values()
1041 .into_iter()
1042 .chain(self.attribute_values())
1043 .find(|(c, _)| *c == column)
1044 .map(|(_, v)| v.to_text())
1045 .unwrap_or_default()
1046 }
1047}
1048
1049#[derive(Debug, Clone, Copy)]
1051pub struct Parent {
1052 pub column: &'static str,
1054 pub table: &'static str,
1056 pub key: &'static str,
1057 pub owner: &'static [(&'static str, &'static str)],
1059}
1060
1061pub(crate) fn by_id<M: Model>(id: Value) -> Query<M> {
1062 Query::new().filter(|_| Expr::Compare {
1063 column: M::PRIMARY_KEY,
1064 op: "=",
1065 value: id,
1066 })
1067}