Skip to content

How To: Define a data model and store history data to database

Bruno P. Kinoshita edited this page Oct 16, 2016 · 1 revision

Dashing is build based on Sinatra, if you are already familiar with Sinatra, then I am sure this won't be a problem.

This guide aims for the people who are not so familiar with Sinatra and want a quick hint.

1. Update Gemfile, add the following lines

gem 'dm-sqlite-adapter'
gem 'data_mapper'

2. Define your data model under lib directory, lib files will be loaded before jobs directory

require "data_mapper"

DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/database.db")

class YourDataModel
  include DataMapper::Resource

  property :id,    Serial    
  property :createdAt, DateTime
  property :serviceName, String
  property :available, Boolean, :default  => true

end

# Perform basic sanity checks and initialize all relationships
# Call this when you've defined all your models
DataMapper.finalize

# automatically create the post table
YourDataModel.auto_upgrade!

3. Use it in your job file

   YourDataModel.new({:createdAt => DateTime.now, :serviceName => 'service1', :available => succeed}).save()
   puts "YourDataModel.all().count #{YourDataModel.all().count}"
  • Home
  • User Guide
    • Installing Dashing
      • Nginx with Passenger
      • Puma
      • Heroku
    • Configuration
      • Add Authentication
      • Change default Dashboard
      • Run on a different port, or in production
      • Run Dashing on a sub path
      • Update Font Awesome fonts from version 3 to 4
    • Widgets
      • Debug incoming widget data
      • Additional Widgets
      • Set up a graph
    • Tips
      • ...
  • Integrations
    • Databases
      • Define a data model and store history data to database
      • Store and data to and display from database
      • Send MySQL data to your widgets
    • Other frameworks and libraries
      • Django
    • Monitoring
      • Dashing
    • CI
      • Jenkins
    • Issue Tracking
      • JIRA
    • Misc
      • Update a dashboard using a spreadsheet
  • Development Instructions
    • Building from source
  • ...
Clone this wiki locally