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
//! `ModelDelegate` batch entry points (`batch_get`, `batch_create`,
//! `batch_update`, `batch_delete`, `batch_upsert`).
use crate::{BatchCreate, BatchDelete, BatchGet, BatchUpdate, BatchUpdateItem, BatchUpsert};
use super::model::ModelDelegate;
impl<'a, M: 'static, PK: 'static> ModelDelegate<'a, M, PK> {
/// Fetch many rows by primary key in a single round-trip; missing
/// rows surface as per-item `NotFound` in the envelope rather
/// than aborting.
pub fn batch_get(&self, ids: Vec<PK>) -> BatchGet<'a, M, PK> {
BatchGet {
runtime: self.runtime,
descriptor: self.descriptor,
ids,
}
}
/// Insert many rows in one outer transaction; each input runs
/// under a nested SAVEPOINT, so a per-item failure (validation,
/// policy, unique conflict) doesn't take down the rest of the
/// batch.
pub fn batch_create<I>(&self, inputs: Vec<I>) -> BatchCreate<'a, M, PK, I> {
BatchCreate {
runtime: self.runtime,
descriptor: self.descriptor,
inputs,
}
}
/// Update many rows in one outer transaction with per-item
/// patches and optional `if_match` versions. Per-item failures
/// roll back at the savepoint; successful items commit together.
pub fn batch_update<I>(&self, items: Vec<BatchUpdateItem<PK, I>>) -> BatchUpdate<'a, M, PK, I> {
BatchUpdate {
runtime: self.runtime,
descriptor: self.descriptor,
items,
}
}
/// Delete many rows by primary key in a single statement; rows
/// that don't exist (or that policy hid) surface as per-item
/// `NotFound`.
pub fn batch_delete(&self, ids: Vec<PK>) -> BatchDelete<'a, M, PK> {
BatchDelete {
runtime: self.runtime,
descriptor: self.descriptor,
ids,
}
}
/// Insert-or-update many rows in one outer transaction with
/// per-item savepoints. Eligible only for models whose `@id` is
/// client-supplied — same compile-time gate as the single-row
/// `.upsert(...)`.
pub fn batch_upsert<I>(&self, inputs: Vec<I>) -> BatchUpsert<'a, M, PK, I> {
BatchUpsert {
runtime: self.runtime,
descriptor: self.descriptor,
inputs,
}
}
}