Hi Jeremy,

Thanks, the problem was that I needed to symbolise all keys in yaml. This 
works fine but now there is another problem. When attempting to connect to 
different hosts it appears to be using the default username. 

  :db1: 
    :adapter: 'tinytds'
    :database: 'db1'
    :host: 'host_one.ab.cd'
    :port: 1433
    :username: 'dev'
    :password: 'abcd1234'
    :mode: 'dblib'
  :db2: 
    :adapter: 'tinytds'
    :database: 'db2'
    :host: 'host_two.ab.cd'
    :port: 1433
    :username: 'dev'
    :password: 'abcd1234'
    :mode: 'dblib'

I've attempted to also use url connection string as well here is an example 
of what I use

def database_url(username, password, host, port, database, mode='dblib')
    
"tinytds://#{username}:#{password}@#{host}:#{port}/#{database}?mode=#{mode}"
end

servers = 
YAML.load_file(File.open('config/database.yml')).fetch(environment)
urls = Hash[servers.map { |server, db| [server, { uri: 
database_url(db[:username], db[:password], db[:host], db[:port], 
db[:database]) }] }]

@sequel = Sequel.connect(urls[:db1][:uri], servers: urls, logger: logger)

the above works only for the default connection, but in the with_server 
block when specifying a the server it ignores it and uses the default.

Thanks

On Wednesday, May 21, 2014 1:06:09 AM UTC+10, Jeremy Evans wrote:
>
> On Monday, May 19, 2014 11:06:43 PM UTC-7, Glen Bray wrote:
>>
>> I'm trying to set up sharding between different customer databases so 
>> this is the code:
>>
>>   def initialize(app)
>>     @app = app
>>     servers = 
>> YAML.load_file(File.open('config/database.yml'))(environment).symbolize_keys!
>>     @sequel = Sequel.connect(servers[:db_dev], servers: servers, logger: 
>> Logger.new("log/#{environment}_db.log"))
>>     @sequel.extension :server_block
>>   end 
>>
>>   def call(env)
>>     customer = find_customer(key).to_sym
>>     puts "customer: #{customer}"
>>
>>     @sequel.with_server(customer) do
>>       env['customer'] = customer
>>       env['db-connection'] = @sequel
>>       @app.call(env)
>>   end
>>
>> Hardcoding a customer name into the with_server block also returns the 
>> default server db_dev. Am I missing something here?
>>
>
> Nothing jumps out at me as being wrong here, but there are a lot of 
> unknown variables (e.g. contents of the servers hash, value of key).  Any 
> chance you can create a self-contained reproducible test case showing the 
> issue?
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to