cubos / rethinkdb.cr

RethinkDB Driver for Crystal
MIT License
34 stars 4 forks source link

Cursor issues #11

Closed kingsleyh closed 6 years ago

kingsleyh commented 6 years ago

Hi

I have a strange Cursor issue.

p my_cursor

#<RethinkDB::Cursor:0x10bead8a0
 @index=1,
 @response=
  #<RethinkDB::Connection::Response:0x10beb0a50
   @b=nil,
   @e=nil,
   @n=[],
   @p=nil,
   @r=
    [{"groupId" => "3dc3cc0e-886e-4ec8-96f2-617fa84ab506", "id" => "4c951ac7-0f89-43a8-8298-749ac76d1a8f", "isLanding" => false, "name" => "channel1"}],
   @t=SUCCESS_SEQUENCE>,
 @stream=
  #<RethinkDB::Connection::ResponseStream:0x10bead990
   @channel=#<Channel::Unbuffered(String):0x10bea7e40>,
   @conn=
    #<RethinkDB::Connection:0x109e04c00
     @channels={},
     @db="jamtalk",
     @next_id=20_u64,
     @next_query_id=1_u64,
     @open=true,
     @sock=#<TCPSocket:fd 9>>,
   @id=0_u64,
   @runopts={"db" => [14_i64, ["jamtalk"]]}>>

p my_cursor.to_a
[]

As you can see I have a cursor which appears to have a result in it. But when I try to convert the cursor to an array so that I can get the result out - it gives me back an empty array

any idea what is going on?

kingsleyh commented 6 years ago

Do you think I should switch to using https://github.com/lbguilherme/rethinkdb-lite/ instead of this library?

lbguilherme commented 6 years ago

This cursor was already consumed (@index=1). Cursors can only be read once. After that they are empty. This is because possibly the cursor can return more data than would fit memory.

About the library, there are still missing many ReQL functions, like between, getAll, concatMap, etc. If you switch now, you won't be able to use many of those for a while.

kingsleyh commented 6 years ago

Hi - yes sorry you are right - I accidentally drained it by doing .to_a to check if it was empty or not earlier in the code! Ok I will keep going here until the other one is ready - I added quite a few more functions like get_fields, eq_join, set_insert, etc to my fork already.