postgres 数据到破折号

postgres data to dashing

是否可以将 postgres 中包含的数据发送到 dashing dashboard?我找到了 mysql 示例 here and same question here.

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

包含在 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