@@ -170,6 +170,19 @@ pub async fn run(ctx, i) {
170
170
}
171
171
```
172
172
173
+ Query parameters can be bound and passed by names as well:
174
+ ```rust
175
+ const INSERT = "my_insert";
176
+
177
+ pub async fn prepare(ctx) {
178
+ ctx.prepare(INSERT, "INSERT INTO test.test(id, data) VALUES (:id, :data)").await?;
179
+ }
180
+
181
+ pub async fn run(ctx, i) {
182
+ ctx.execute_prepared(INSERT, #{id: 5, data: "foo"}).await
183
+ }
184
+ ```
185
+
173
186
### Populating the database
174
187
175
188
Read queries are more interesting when they return non-empty result sets.
@@ -209,18 +222,20 @@ are pure, i.e. invoking them multiple times with the same parameters yields alwa
209
222
- `latte::hash_select(i, vector)` – selects an item from a vector based on a hash
210
223
- `latte::blob(i, len)` – generates a random binary blob of length `len`
211
224
- `latte::normal(i, mean, std_dev)` – generates a floating point number from a normal distribution
212
-
213
- #### Numeric conversions
214
-
215
- Rune represents integers as 64-bit signed values. Therefore, it is possible to directly pass a Rune integer to
216
- a Cassandra column of type `bigint`. However, binding a 64-bit value to smaller integer column types, like
217
- `int`, `smallint` or `tinyint` will result in a runtime error. As long as an integer value does not exceed the bounds,
218
- you can convert it to smaller signed integer types by using the following instance functions:
219
-
220
- - `x.to_i32()` – converts a float or integer to a 32-bit signed integer, compatible with Cassandra `int` type
221
- - `x.to_i16()` – converts a float or integer to a 16-bit signed integer, compatible with Cassandra `smallint` type
222
- - `x.to_i8()` – converts a float or integer to an 8-bit signed integer, compatible with Cassandra `tinyint` type
223
- - `x.clamp(min, max)` – restricts the range of an integer or a float value to given range
225
+ - `latte::uniform(i, min, max)` – generates a floating point number from a uniform distribution
226
+
227
+ #### Type conversions
228
+ Rune uses 64-bit representation for integers and floats.
229
+ Since version 0.28 Rune numbers are automatically converted to proper target query parameter type,
230
+ therefore you don' t need to do explicit conversions. E.g. you can pass an integer as a parameter
231
+ of Cassandra type ` smallint` . If the number is too big to fit into the range allowed by the target
232
+ type, a runtime error will be signalled.
233
+
234
+ The following methods are available:
235
+ - `x.to_integer ()` – converts a float to an integer
236
+ - ` x.to_float()` – converts an integer to a float
237
+ - ` x.to_string()` – converts a float or integer to a string
238
+ - ` x.clamp(min, max)` – restricts the range of an integer or a float value to given range
224
239
225
240
You can also convert between floats and integers by calling ` to_integer` or ` to_float` instance functions.
226
241
0 commit comments