hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! One paged `SELECT` — the window and the `total` that goes with it, both |
| 2 | //! done by the database. |
| 3 | //! |
| 4 | //! WHY: `?limit=10` used to run an unbounded `SELECT *`, hand the whole table |
| 5 | //! to the web layer and slice ten rows off it. The scan (and the decode of |
| 6 | //! every row) grew with the table no matter how small the page was. Here the |
| 7 | //! window is `LIMIT/OFFSET` in SQL, and `total` is a `count(*)` over the |
| 8 | //! *same* `WHERE` as a second statement, so a page can never disagree with |
| 9 | //! the count that pages it. |
| 10 | //! |
| 11 | //! ```ignore |
| 12 | //! PagedList::new("note WHERE user_id = $1", "ORDER BY id DESC") |
| 13 | //! .bind(owner.0) |
| 14 | //! .run::<Note>(limit, offset, db) |
| 15 | //! .await |
| 16 | //! ``` |
| 17 | //! |
| 18 | //! Paging stays opt-in: `limit = None, offset = 0` is the unpaged read, and |
| 19 | //! it runs exactly one statement (no count — the rows in hand *are* the |
| 20 | //! total), so internal callers that just want the list pay nothing. |
| 21 | //! |
| 22 | //! Runtime-checked SQL by design: `from_where` is assembled per call site, |
| 23 | //! which is this module's named exemption from the compile-time `query!` |
| 24 | //! rule. Placeholders are positional (`$1, $2, …`) in [`.bind`] order, and |
| 25 | //! the window's own placeholders continue the numbering. The count is a plain |
| 26 | //! `count(*)`, which always answers one `NOT NULL` row — no planner-shape |
| 27 | //! decoding to preserve. |
| 28 | //! |
| 29 | //! The dynamic parts of every statement here are table/column names (in-crate |
| 30 | //! constants and literals, never client text) and the `$n` numbers this |
| 31 | //! builder prints itself; every value binds — which is the audit the |
| 32 | //! [`AssertSqlSafe`] wraps stand on. |
| 33 | //! |
| 34 | //! Only for lists the database can express whole. A handler that filters rows |
| 35 | //! in Rust after the read (visibility, audience resolution, a schedule |
| 36 | //! window) must keep slicing in the web layer: a DB `LIMIT` in front of a |
| 37 | //! Rust filter silently returns a short page. |
| 38 | |
| 39 | use ; |
| 40 | use ; |
| 41 | use Uuid; |
| 42 | |
| 43 | use crateDatabase; |
| 44 | use crateAppError; |
| 45 | |
| 46 | /// One bound parameter of a runtime-checked builder's statement, in |
| 47 | /// `$1, $2, …` order. |
| 48 | /// |
| 49 | /// [`PagedList`] and [`crate::db::field_update::FieldUpdate`] are the named |
| 50 | /// exemptions from the compile-time `query!` rule: their SQL is assembled at |
| 51 | /// run time, so their parameters ride this closed enum — owned values, no |
| 52 | /// borrow to tie a builder's lifetime to, [`Clone`] because one builder run |
| 53 | /// can need the same `WHERE` bound twice (page, then count). A caller that |
| 54 | /// needs a type the enum lacks adds a variant here; sqlx's borrow-tied |
| 55 | /// dynamic binding does not survive being stored in a builder. |
| 56 | |
| 57 | pub |
| 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 | pub |
| 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 |