Skip to content

Instantly share code, notes, and snippets.

@nandayadav
Created September 1, 2011 04:13
Show Gist options
  • Save nandayadav/1185433 to your computer and use it in GitHub Desktop.
Save nandayadav/1185433 to your computer and use it in GitHub Desktop.
Goliath endpoint using activerecord
require "rubygems"
require "bundler/setup" #using bundler for dependencies
#echo_with_ar.rb
require 'goliath'
require 'active_record'
class User < ActiveRecord::Base
end
class EchoWithAr < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::DefaultMimeType
use Goliath::Rack::Render, 'json'
def response(env)
#user = User.find(1).to_json
User.connection.execute("SELECT sleep(1.0)")
ActiveRecord::Base.clear_active_connections!
[200, {}, "slept"]
end
end
#config/echo_with_ar.rb
require 'em-synchrony/activerecord'
ActiveRecord::Base.establish_connection(:adapter => 'em_mysql2',
:database => 'goliath_app',
:username => 'root',
:password => '',
:reconnect => true,
:pool => 10,
:wait_timeout => 0.5,
:host => 'localhost')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment