Skip to content

Add syntactic sugar to get array instead of cursor  #31

Closed

Description

@cesarandreu

I'm using this lib with koa and it's annoying to have to yield twice to get the full array.

I would love a way to yield just once and have it return the full array. I'm unsure of what the best syntax for this would be, but something like the following would be great:

let arr = yield r.expr([1, 2, 3]).run().toArray();
console.log(arr); // print [1,2,3]

In the case of someone yielding on something that returns a single value, perhaps it would just return an array with the item?

let arr = yield r.expr(1).run().toArray();
console.log(arr); // print [1]

I'm willing to look into it and attempt creating a PR if you'd be interested in it. I'm also flexible on the syntax for it, I chose adding .toArray() at the end because it's very similar to what's already available.

Activity

  1. neumino commented on Jun 30, 2014

    @neumino
    Owner

    Just for the record, we discussed a bit on IRC with @cesarandreu

    I'm thinking of doing something similar to what thinky is doing by introducing an execute command.

    query.run().then(function(result) {
        // a value or an array
        // run() automatically coerce cursors to array
    })
    
    query.execute().then(function(result) {
       // execute would have the current behavior of `run`.
    })
    

    The thing is if we go for this solution, rethinkdbdash will start moving away from the official driver, and I've somehow tried to stay close to the official driver for now.
    I'll think about it : )

  2. cesarandreu commented on Jul 2, 2014

    @cesarandreu
    Author

    Maybe it'd make more sense to reverse them?

    Have run continue returning a cursor, and execute could return the whole result.

    That way it's consistent with the official driver, but it provides the added functionality.

  3. thelinuxlich commented on Jul 28, 2014

    @thelinuxlich

    +1

  4. neumino commented on Aug 8, 2014

    @neumino
    Owner

    I plan to push that for 1.14.

  5. added a commit that references this issue on Aug 19, 2014
    fd75d97
  6. thelinuxlich commented on Aug 26, 2014

    @thelinuxlich

    great!

  7. neumino commented on Aug 26, 2014

    @neumino
    Owner

    Released in 1.14

  8. cesarandreu commented on Aug 26, 2014

    @cesarandreu
    Author

    \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions