Created
January 7, 2012 20:01
-
-
Save joaodrp/1575846 to your computer and use it in GitHub Desktop.
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
# | |
# Inside Config file | |
# | |
backend_map = {'mongodb' => MyProject::Backends::MongoDB, | |
'mysql' => MyProject::Backends::MySQL} | |
conf = load_some_yaml_file_with_a_backend_URI_parameter() | |
uri = conf[:backend] | |
backend_name = uri.split(':').first | |
config['backend_class'] = backend_map[backend_name] | |
config['uri'] = uri | |
config['db'] = | |
if backend_name == 'mysql' | |
EventMachine::Synchrony::ConnectionPool.new(size: 10) do | |
Mysql2::EM::Client.new(...) | |
end | |
elsif backend_name == 'mongodb' | |
EventMachine::Synchrony::ConnectionPool.new(size: 10) do | |
# setup mongo connection | |
end | |
end | |
# ----------------------------- | |
# | |
# Inside Goliath server file | |
# | |
# after modify my backend classes to accept a 'conn' instance variable and use that inside of its methods instead | |
# of create a connection at each call | |
DB = backend_class.connect(uri: uri, conn: db) # and use it inside of routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment