postgres数据以潇洒

时间:2015-05-17 06:40:01

标签: sinatra dashing

是否可以将postgres中包含的数据发送到仪表板?我找到了mysql示例here和同样的问题here

我在jobs文件夹中编辑了我的工作。我还包括 pg gem。

require 'pg'
conn = PGconn.new(:host => "10.10.8.10", :port => "5432",:dbname => "db1",:login => "test",:password => "test")
results  = conn.exec("select partner,sitetype from test")
# Sending to List widget, so map to :label and :value
  acctitems = results.map do |row|
    row = {
      :label => row['partner'],
      :value => row['sitetype']
    }
  end

  # Update the List widget
  send_event('account_count', { items: acctitems } )

end

1 个答案:

答案 0 :(得分:1)

包含在Gemfile中:

gem 'pg'

在你的jobs.rb文件中:

require 'pg'

SCHEDULER.every '3m', :first_in => 0 do |job|
conn = PGconn.new(:host => "localhost", :port => "5432",:dbname => "dbname",:user => "test",:password => "test")
results  = conn.exec("select partner,sitetype from test")
# Sending to List widget, so map to :label and :value
  acctitems = results.map do |row|
    row = {
      :label => row['partner'],
      :value => row['sitetype']
    }
  end

  # Update the List widget
  send_event('account_count', { items: acctitems } )

end