Sha256: a6d593dfa5f940f6184889143ee38be130aaf6ad7333f2d2e4469ac327b3b553

Contents?: true

Size: 668 Bytes

Versions: 9

Compression:

Stored size: 668 Bytes

Contents

require 'sequel'
Sequel::Model.plugin(:schema)

DB = Sequel.connect("sqlite:///#{__DIR__}/../blog.db")

class Entry < Sequel::Model(:entry)
  set_schema do
    primary_key :id

    time :created
    time :updated
    text :title
    text :content
  end

  def self.add(title, content)
    create :title => title, :content => content,
      :created => Time.now, :updated => Time.now
  end

  def update(title = title, content = content)
    self.title, self.content, self.updated = title, content, Time.now
    save
  end
end

Entry.create_table! unless Entry.table_exists?

if Entry.empty?
  Entry.add 'Blog created', 'Exciting news today, this blog was created'
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
starapor-slippers-0.0.5 examples/blog/model/entry.rb
starapor-slippers-0.0.6 examples/blog/model/entry.rb
starapor-slippers-0.0.8 examples/blog/model/entry.rb
starapor-slippers-0.0.9 examples/blog/model/entry.rb
slippers-0.0.14 examples/blog/model/entry.rb
slippers-0.0.13 examples/blog/model/entry.rb
slippers-0.0.12 examples/blog/model/entry.rb
slippers-0.0.11 examples/blog/model/entry.rb
slippers-0.0.10 examples/blog/model/entry.rb