rethinkdb-rs icon indicating copy to clipboard operation
rethinkdb-rs copied to clipboard

parse single array as sequence when response type is SUCCESS_ATOM

Open vettich opened this issue 2 years ago • 1 comments
trafficstars

There was a problem with queries:

Simple get all items in table

let mut cur = r.table(name).run::<_, T>(conn);
let mut res: Vec<T> = vec![];
while let Some(val) = cur.try_next().await? {
    res.push(val);
}
//...

and with order_by

let mut cur = r.table(name).order_by("created_at").run::<_, T>(conn);
let mut res: Vec<T> = vec![];
while let Some(val) = cur.try_next().await? {
    res.push(val);
}
// ...

In both cases, in the while, I expect an enumeration of the elements in the table. But when I try to sort with order_by, rethinkdb returns not SUCCESS_SEQUENCE with an array of elements ([1, 2, 3, ...]), but returns SUCCESS_ATOM with an array of one element of the elements array ([[1, 2, 3, ...]]). So in the second case I had a JSON parsing error

I tried to bring this to the one expected form: to a simple array of elements [1, 2, 3, ...]

vettich avatar Jan 02 '23 04:01 vettich

A similar implementation is used in the go library https://github.com/rethinkdb/rethinkdb-go/blob/master/cursor.go#L692

vettich avatar Jan 02 '23 05:01 vettich