Module: Sinatra::SequelExtension
- Defined in:
- lib/sinatra/sequel.rb
Instance Method Summary collapse
- #database ⇒ Object
- #database=(url) ⇒ Object
- #migration(name, &block) ⇒ Object
-
#postgres? ⇒ Boolean
TODO: wrong!.
- #sqlite? ⇒ Boolean
Instance Method Details
#database ⇒ Object
19 20 21 22 |
# File 'lib/sinatra/sequel.rb', line 19 def database @database ||= Sequel.connect(database_url) end |
#database=(url) ⇒ Object
13 14 15 16 17 |
# File 'lib/sinatra/sequel.rb', line 13 def database=(url) @database = nil set :database_url, url database end |
#migration(name, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/sinatra/sequel.rb', line 33 def migration(name, &block) create_migrations_table return if database[migrations_table_name].filter(:name => name).count > 0 migrations_log.puts "Running migration: #{name}" database.transaction do yield database database[migrations_table_name] << { :name => name, :ran_at => Time.now } end end |
#postgres? ⇒ Boolean
TODO: wrong!
29 30 31 |
# File 'lib/sinatra/sequel.rb', line 29 def postgres? ! sqlite? end |
#sqlite? ⇒ Boolean
24 25 26 |
# File 'lib/sinatra/sequel.rb', line 24 def sqlite? defined?(Sequel::SQLite::Database) && database.kind_of?(Sequel::SQLite::Database) end |