Created
June 24, 2016 19:28
-
-
Save bjfish/bc3fc128f000b21e3c66c787d5d663a2 to your computer and use it in GitHub Desktop.
Sinatra + RethinkDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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