2

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

我在工作文件夹中编辑了我的工作。我还包括了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
4

1 回答 1

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
于 2015-05-18T01:27:43.130 回答