Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rethinkdb? #204

Open
miguelalarcos opened this issue Apr 10, 2016 · 3 comments
Open

Support Rethinkdb? #204

miguelalarcos opened this issue Apr 10, 2016 · 3 comments

Comments

@miguelalarcos
Copy link

I was wondering if there are plans to support Rethinkdb.

Thanks for the good job!

@dgutov
Copy link
Collaborator

dgutov commented Apr 10, 2016

This discussion seems relevant: rethinkdb/rethinkdb#4630

@igrigorik
Copy link
Owner

I'd be happy to accept a PR if someone wants to own it on an on-going basis.

@miguelalarcos
Copy link
Author

What about this as a starting point? (the important funcs are rsync and rmsync)

require 'eventmachine'
require 'fiber'
require 'rethinkdb'

$r = RethinkDB::RQL.new
$conn = $r.connect()

def get_array predicate
  ret = []
  docs_with_count(predicate) do |count, row|
    ret << row
    yield ret if ret.length == count
  end
end

def docs_with_count predicate
  predicate.count().em_run($conn) do |count|
    predicate.em_run($conn) do |doc|
      yield count, doc
    end
  end
end

def rsync pred
  aux = Fiber.new do |current|
    pred.em_run($conn) do |doc|
      current.transfer doc
    end
  end
  aux.transfer Fiber.current
end

def rmsync pred
  aux = Fiber.new do |current|
    get_array(pred){|docs| current.transfer docs}
  end
  aux.transfer Fiber.current
end

fib = Fiber.new do
  doc = rsync $r.table('aux').get('94fcf756-ae81-4eb6-a50e-4004717c948a')
  print doc
  puts
  docs = rmsync $r.table('aux')
  print docs
  puts
  EM.stop
end

EM.run do
  fib.resume
end

Sorry if the code is not clear enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants