Created
September 1, 2011 04:13
-
-
Save nandayadav/1185433 to your computer and use it in GitHub Desktop.
Goliath endpoint using activerecord
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 "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