Method __builtin.Sql.Connection()->promise_query()
class__builtin.Sql.Connection
- Method
promise_query
variant__experimental__Concurrent.Future(<.Result>) promise_query(stringq,void|zero|mapping(string|int:mixed)bindings,void|zero|function(array,.Result,array:array)map_cb,void|zero|mapping(string:int)options)- Description
Sends a typed query to the database asynchronously.
- Returns
A Concurrent.Future carrying a buffered Sql.Result. A failed query rejects the future with an error. The result cursor starts at the first row. Use res_obj_to_array() to convert the result to labeled rows.
- Parameter
bindings Bindings for the query.
- Parameter
map_cb Called for every row returned. The arguments are the row, the result object, and the rows already collected. Return the modified row, or
0to discard it.- Parameter
options Optional mapping with the following keys:
"min_records":intFail if fewer rows are returned. Defaults to
0."max_records":intFail if more rows are returned.
-1disables the limit."discard_records":intKeep at most this many rows.
-1keeps all rows.- Example
Sql.Connection db = Sql.Sql("mysql://localhost/testdb"); Concurrent.Future(<Sql.Result>) query = db->promise_query("SELECT 42", 0, 0, (["max_records":10])); query->on_success(lambda (Sql.Result result) { werror("Got %O\n", result->fetch_row()); }); query->on_failure(lambda (mixed error) { werror("Query failed: %O\n", error); });- See also