Created
December 9, 2012 18:24
-
-
Save bontoJR/4246365 to your computer and use it in GitHub Desktop.
data_mapper configuration for Sinatra (over Rack) web app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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