Skip to main content

prax_query/inputs/
args.rs

1//! Per-operation argument containers.
2//!
3//! Each struct is the layer-2 "explicit form" of an operation request:
4//! the macro DSL (phase 3+) expands to a `*Args { ... }` literal that
5//! the operation builder consumes via `.with_args(args)`. Direct
6//! construction by hand is fully supported.
7//!
8//! Generic parameters:
9//! - `M` — the model
10//! - `W` — `WhereInput` impl for that model
11//! - `I` — `IncludeInput` impl
12//! - `S` — `SelectInput` impl
13//! - `D` — `CreateInput::Data` / `UpdateInput::Data` payload (operation-specific)
14//! - `O` — `OrderByInput` impl
15//!
16//! Phase 1 keeps the bounds open so hand-construction works even before
17//! codegen lands. Phase 2 narrows them when the per-model types exist.
18
19use core::marker::PhantomData;
20
21/// Args for `find_unique`. `where` must identify at most one row.
22#[derive(Debug, Clone)]
23pub struct FindUniqueArgs<M, W, I, S> {
24    /// Unique WHERE input.
25    pub r#where: W,
26    /// Optional include shape.
27    pub include: Option<I>,
28    /// Optional select shape.
29    pub select: Option<S>,
30    /// Phantom marker for the model type.
31    #[doc(hidden)]
32    pub _model: PhantomData<M>,
33}
34
35impl<M, W: Default, I, S> Default for FindUniqueArgs<M, W, I, S> {
36    fn default() -> Self {
37        Self {
38            r#where: W::default(),
39            include: None,
40            select: None,
41            _model: PhantomData,
42        }
43    }
44}
45
46impl<M, W, I, S> FindUniqueArgs<M, W, I, S> {
47    /// Construct with the given unique WHERE.
48    pub fn new(r#where: W) -> Self {
49        Self {
50            r#where,
51            include: None,
52            select: None,
53            _model: PhantomData,
54        }
55    }
56}
57
58/// Args for `find_first`.
59#[derive(Debug, Clone)]
60pub struct FindFirstArgs<M, W, I, S, O = (), C = ()> {
61    /// Optional WHERE input.
62    pub r#where: Option<W>,
63    /// Optional include shape.
64    pub include: Option<I>,
65    /// Optional select shape.
66    pub select: Option<S>,
67    /// Optional order-by shape (single or vec).
68    pub order_by: Option<Vec<O>>,
69    /// Optional cursor value.
70    pub cursor: Option<C>,
71    /// Skip N rows.
72    pub skip: Option<u64>,
73    /// Take N rows.
74    pub take: Option<u64>,
75    /// Phantom marker for the model.
76    #[doc(hidden)]
77    pub _model: PhantomData<M>,
78}
79
80impl<M, W, I, S, O, C> Default for FindFirstArgs<M, W, I, S, O, C> {
81    fn default() -> Self {
82        Self {
83            r#where: None,
84            include: None,
85            select: None,
86            order_by: None,
87            cursor: None,
88            skip: None,
89            take: None,
90            _model: PhantomData,
91        }
92    }
93}
94
95/// Args for `find_many`.
96#[derive(Debug, Clone)]
97pub struct FindManyArgs<M, W, I, S, O = (), C = ()> {
98    /// Optional WHERE input.
99    pub r#where: Option<W>,
100    /// Optional include shape.
101    pub include: Option<I>,
102    /// Optional select shape.
103    pub select: Option<S>,
104    /// Optional order-by shape (single or vec).
105    pub order_by: Option<Vec<O>>,
106    /// Optional cursor value.
107    pub cursor: Option<C>,
108    /// Skip N rows.
109    pub skip: Option<u64>,
110    /// Take N rows.
111    pub take: Option<u64>,
112    /// Distinct columns.
113    pub distinct: Option<Vec<String>>,
114    /// Phantom marker for the model.
115    #[doc(hidden)]
116    pub _model: PhantomData<M>,
117}
118
119impl<M, W, I, S, O, C> Default for FindManyArgs<M, W, I, S, O, C> {
120    fn default() -> Self {
121        Self {
122            r#where: None,
123            include: None,
124            select: None,
125            order_by: None,
126            cursor: None,
127            skip: None,
128            take: None,
129            distinct: None,
130            _model: PhantomData,
131        }
132    }
133}
134
135/// Args for `create`.
136#[derive(Debug, Clone)]
137pub struct CreateArgs<M, D, I, S> {
138    /// Create-data payload.
139    pub data: D,
140    /// Optional include shape on the returning row.
141    pub include: Option<I>,
142    /// Optional select shape on the returning row.
143    pub select: Option<S>,
144    /// Phantom marker for the model.
145    #[doc(hidden)]
146    pub _model: PhantomData<M>,
147}
148
149impl<M, D: Default, I, S> Default for CreateArgs<M, D, I, S> {
150    fn default() -> Self {
151        Self {
152            data: D::default(),
153            include: None,
154            select: None,
155            _model: PhantomData,
156        }
157    }
158}
159
160/// Args for `create_many`.
161#[derive(Debug, Clone)]
162pub struct CreateManyArgs<M, D> {
163    /// Create-data payloads.
164    pub data: Vec<D>,
165    /// Skip rows that would violate a unique constraint (instead of erroring).
166    pub skip_duplicates: Option<bool>,
167    /// Phantom marker for the model.
168    #[doc(hidden)]
169    pub _model: PhantomData<M>,
170}
171
172impl<M, D> Default for CreateManyArgs<M, D> {
173    fn default() -> Self {
174        Self {
175            data: Vec::new(),
176            skip_duplicates: None,
177            _model: PhantomData,
178        }
179    }
180}
181
182/// Args for `update`.
183#[derive(Debug, Clone)]
184pub struct UpdateArgs<M, W, U, I, S> {
185    /// Unique WHERE input.
186    pub r#where: W,
187    /// Update-data payload.
188    pub data: U,
189    /// Optional include shape.
190    pub include: Option<I>,
191    /// Optional select shape.
192    pub select: Option<S>,
193    /// Phantom marker for the model.
194    #[doc(hidden)]
195    pub _model: PhantomData<M>,
196}
197
198/// Args for `update_many`.
199#[derive(Debug, Clone)]
200pub struct UpdateManyArgs<M, W, U> {
201    /// Optional WHERE input.
202    pub r#where: Option<W>,
203    /// Update-data payload.
204    pub data: U,
205    /// Phantom marker for the model.
206    #[doc(hidden)]
207    pub _model: PhantomData<M>,
208}
209
210impl<M, W, U: Default> Default for UpdateManyArgs<M, W, U> {
211    fn default() -> Self {
212        Self {
213            r#where: None,
214            data: U::default(),
215            _model: PhantomData,
216        }
217    }
218}
219
220/// Args for `upsert`.
221#[derive(Debug, Clone)]
222pub struct UpsertArgs<M, W, C, U, I, S> {
223    /// Unique WHERE input.
224    pub r#where: W,
225    /// Create-data payload (used if no row matched).
226    pub create: C,
227    /// Update-data payload (used if a row matched).
228    pub update: U,
229    /// Optional include shape on the returning row.
230    pub include: Option<I>,
231    /// Optional select shape on the returning row.
232    pub select: Option<S>,
233    /// Phantom marker for the model.
234    #[doc(hidden)]
235    pub _model: PhantomData<M>,
236}
237
238/// Args for `delete`.
239#[derive(Debug, Clone)]
240pub struct DeleteArgs<M, W, I, S> {
241    /// Unique WHERE input.
242    pub r#where: W,
243    /// Optional include shape on the returning row.
244    pub include: Option<I>,
245    /// Optional select shape on the returning row.
246    pub select: Option<S>,
247    /// Phantom marker for the model.
248    #[doc(hidden)]
249    pub _model: PhantomData<M>,
250}
251
252/// Args for `delete_many`.
253#[derive(Debug, Clone, Default)]
254pub struct DeleteManyArgs<M, W> {
255    /// Optional WHERE input.
256    pub r#where: Option<W>,
257    /// Phantom marker for the model.
258    #[doc(hidden)]
259    pub _model: PhantomData<M>,
260}
261
262/// Args for `count`.
263#[derive(Debug, Clone, Default)]
264pub struct CountArgs<M, W, O = (), C = ()> {
265    /// Optional WHERE input.
266    pub r#where: Option<W>,
267    /// Optional order-by.
268    pub order_by: Option<Vec<O>>,
269    /// Optional cursor.
270    pub cursor: Option<C>,
271    /// Skip N rows.
272    pub skip: Option<u64>,
273    /// Take N rows.
274    pub take: Option<u64>,
275    /// Phantom marker for the model.
276    #[doc(hidden)]
277    pub _model: PhantomData<M>,
278}
279
280/// Args for `aggregate`. The aggregate spec parameter is filled in by phase 6.
281#[derive(Debug, Clone, Default)]
282pub struct AggregateArgs<M, W, A, O = (), C = ()> {
283    /// Optional WHERE input.
284    pub r#where: Option<W>,
285    /// Aggregate spec (`_count` / `_avg` / `_sum` / `_min` / `_max`).
286    pub aggregate: Option<A>,
287    /// Optional order-by.
288    pub order_by: Option<Vec<O>>,
289    /// Optional cursor.
290    pub cursor: Option<C>,
291    /// Skip N rows.
292    pub skip: Option<u64>,
293    /// Take N rows.
294    pub take: Option<u64>,
295    /// Phantom marker for the model.
296    #[doc(hidden)]
297    pub _model: PhantomData<M>,
298}
299
300/// Args for `group_by`. The grouping spec parameter is filled in by phase 6.
301#[derive(Debug, Clone, Default)]
302pub struct GroupByArgs<M, W, A, G, H = (), O = ()> {
303    /// Group by these field names.
304    pub by: Vec<G>,
305    /// Optional WHERE input.
306    pub r#where: Option<W>,
307    /// Optional HAVING input.
308    pub having: Option<H>,
309    /// Aggregate spec.
310    pub aggregate: Option<A>,
311    /// Optional order-by.
312    pub order_by: Option<Vec<O>>,
313    /// Skip N rows.
314    pub skip: Option<u64>,
315    /// Take N rows.
316    pub take: Option<u64>,
317    /// Phantom marker for the model.
318    #[doc(hidden)]
319    pub _model: PhantomData<M>,
320}