Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Add rethinkdb to Gemfile
# Add to boot.rb: autoload :RethinkDB, 'rethinkdb'
# Set up RabbitMQ queue as well
# Load database settings
config = (YAML.load_file('./config/database.yml') || {})[App.env]
# Connect database
if config
# Read settings or load defaults
name = "#{config['name'] || App.name}_#{App.env}"
# Connect rethinkdb
include RethinkDB::Shortcuts
r.connect(:host => 'localhost', :port => 28015, :db => name).repl
# Create database unless it exists
r.db_create(name).run unless r.db_list.run.include?(name)
# Create tables
table_list = r.db(name).table_list.run
%w[projects].each do |table|
r.db(name).table_create(table).run unless table_list.include?(table)
end
# Listen for changes
cursor = r.table('projects').changes
Thread.new do
cursor.run.each do |document|
token = 'BNquxwicvgrVJxdBidmiIA'
App.channel.publish(token, document.to_json)
end
end
else
puts "Database settings not found for #{App.env} in config/database.yml"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.