Skip to content

Instantly share code, notes, and snippets.

@bjfish
Created June 24, 2016 19:28
Show Gist options
  • Save bjfish/bc3fc128f000b21e3c66c787d5d663a2 to your computer and use it in GitHub Desktop.
Save bjfish/bc3fc128f000b21e3c66c787d5d663a2 to your computer and use it in GitHub Desktop.
Sinatra + RethinkDB
require 'sinatra'
require 'rethinkdb'
include RethinkDB::Shortcuts
before do
begin
@c = r.connect(:host=>"localhost", :port=>28015)
rescue Exception => err
puts "Connection erro #{rdb_config[:host]}:#{rdb_config[:port]} (#{err.message})"
halt 500, 'DB Error'
end
end
after do
begin
#@c.close if @c
rescue
puts "Connection close error"
end
end
get '/hi' do
result = ""
#c = r.connect(:host=>"localhost", :port=>28015)
cursor = r.table("authors").filter{|author| author["name"].eq("William Adama") }.run(@c)
cursor.each{|document| result += document.to_s + "\n" }
result += RUBY_ENGINE
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment