@@ -90,15 +90,15 @@ If you're not comfortable with rust's async streams, you can always start using
90
90
The optional ` .condition(...) ` method can be invoked to add a condition the returned rows must satisfy.
91
91
92
92
!!! note
93
- This direclty corresponds to adding a ` WHERE ` clause in sql
93
+ This directly corresponds to adding a ` WHERE ` clause in sql
94
94
95
95
To construct conditions use a comparison method on the field syntax
96
96
```
97
97
User::F.username.equals("bob")
98
- ^^^^^^^^^^ ^^^^^ - Value to compare against
99
- | ^^^^^^
100
- | |
101
- | Comparison operator
98
+ ^^^^^^^^^^^^^^^^ ^^^^^ - Value to compare against
99
+ | ^^^^^^
100
+ | |
101
+ | Comparison operator
102
102
|
103
103
Field to compare
104
104
```
@@ -125,7 +125,7 @@ In its most basic usage (`query!(db, User)`) the query will select every column
125
125
This can be customized by changing the macro's second argument.
126
126
127
127
!!! note
128
- The ` query! ` macro is somewhat unique with regards to its second argument.
128
+ The ` query! ` macro is somewhat unique in regard to its second argument.
129
129
130
130
The other macros won't behave comparibly.
131
131
@@ -160,16 +160,38 @@ let posts: Vec<(String, String)> =
160
160
```
161
161
162
162
When you want to select your relations' fields and there are a lot of them, specifying them all like this can get quite verbose.
163
- On top of that due to rust limitations regarding tuples the is a maximum length of 32 on how many fields you can query in one go.
164
- To mitigate this there is a in between syntax combining individual fields with patches:
163
+ On top of that, due to rust limitations regarding tuples, the maximum number of fields you can query in one go is 32 .
164
+ To mitigate this, there is a syntax combining individual fields with patches:
165
165
166
166
``` rust
167
167
let posts : Vec <(String , UserWithoutPassword )> =
168
168
query! (db , (Post :: F . message, Post :: F . user as UserWithoutPassword )). all (). await ? ;
169
169
```
170
170
171
- ### TODO
172
- ` limit ` , ` offset ` , ` range ` , ` order_... `
171
+ #### Limit & offset
172
+
173
+ Just as you would expect them, the ` .limit(u64) ` and ` .offset(u64) ` functions can be used to add limits and offsets
174
+ to the SQL query. Note that ` .limit() ` can not be combined with ` .one() ` , since the latter already adds a limit of 1.
175
+ Also, the ` .offset() ` can not be used without a limit. The following examples illustrate possible uses:
176
+
177
+ ``` rust
178
+ query! (db , Post ). limit (10 ). all (). await ? ;
179
+ query! (db , Post ). offset (13 ). one (). await ? ;
180
+ query! (db , Post ). limit (10 ). offset (42 ). all (). await ? ;
181
+ query! (db , Post ). limit (100 ). offset (1337 ). stream ();
182
+ ```
183
+
184
+ There is also the ` .range() ` function which provides a convenient way to add both the limit and offset.
185
+ Mixing a range with the previous functions for limit and offset is not allowed.
186
+ Thus, the following example will return at most 10 elements since it corresponds to limit 10 and offset 30:
187
+
188
+ ``` rust
189
+ query! (db , Post ). range (30 .. 40 ). all (). await ? ;
190
+ ```
191
+
192
+ #### Ordering
193
+
194
+ TODO: ` order_... `
173
195
174
196
## Insert
175
197
@@ -347,7 +369,7 @@ async fn update_user(
347
369
348
370
## Delete
349
371
350
- In order to create new rows in the database the ` delete! ` macro is used:
372
+ In order to delete rows from a table, the ` delete! ` macro is used:
351
373
352
374
``` rust
353
375
pub async fn delete_single_user (db : & Database , user : & UserPatch ) -> Result <(), rorm :: Error > {
0 commit comments