Skip to content

Instantly share code, notes, and snippets.

@bontoJR
Created December 9, 2012 18:24
Show Gist options
  • Save bontoJR/4246365 to your computer and use it in GitHub Desktop.
Save bontoJR/4246365 to your computer and use it in GitHub Desktop.
data_mapper configuration for Sinatra (over Rack) web app
require 'sinatra/base'
require 'sinatra/json'
require 'data_mapper'
#If you want the logs displayed you have to do this before the call to setup
DataMapper::Logger.new($stdout, :debug)
#Set the default lenght of String
DataMapper::Property::String.length(255)
#Raise error when save fails
DataMapper::Model.raise_on_save_failure = true
#Setup the DB
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db")
class Post
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :title, String
property :subtitle, String
property :content, Text
property :created_at, DateTime
property :updated_at, DateTime
end
DataMapper.finalize
Post.auto_upgrade!
class MyBlog < Sinatra::Base
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment