diff --git a/lib/rails_sequel.rb b/lib/rails_sequel.rb index 1e0d998..84314aa 100644 --- a/lib/rails_sequel.rb +++ b/lib/rails_sequel.rb @@ -1,4 +1,4 @@ -gem 'sequel' +# gem 'sequel' require 'sequel' require File.expand_path(File.dirname(__FILE__) + '/rails_sequel/rails_sequel') diff --git a/lib/rails_sequel/rails_sequel.rb b/lib/rails_sequel/rails_sequel.rb index 8d18ac5..d1c2f1a 100644 --- a/lib/rails_sequel/rails_sequel.rb +++ b/lib/rails_sequel/rails_sequel.rb @@ -5,7 +5,11 @@ module SequelConnection # Connects to database using constructed Database Connection URI def self.connect - Sequel.connect uri, :loggers => [Rails.logger] + options = self.prepare_options + connection = Sequel.connect(options) + if options[:adapter] == 'mysql' + connection.execute("SET SQL_AUTO_IS_NULL=0") + end end # Returns loaded database.yml configuration for current environment @@ -14,14 +18,29 @@ def self.config end # Constructs Database Connection URI - def self.uri - uri = config[:adapter] << "://" - uri << config[:username] if config[:username] - uri << ':' << config[:password] if config[:password] - uri << '@' if config[:username] || config[:password] - uri << ':' << config[:port] if config[:port] - uri << (config[:host] || 'localhost') - uri << '/' << config[:database] + def self.prepare_options + options = {} + + # Use SQLite by default + options[:adapter] = (config[:adapter] || "sqlite") + # Use localhost as default host + options[:host] = (config[:host] || "localhost") + # Default user is an empty string. Both username and user keys are supported. + options[:user] = (config[:username] || config[:user] || "") + + options[:password] = config[:password] || "" + + # Both encoding and charset options are supported, default is utf8 + options[:encoding] = (config[:encoding] || config[:charset] || "utf8") + # Default database is hey_dude_configure_your_database + options[:database] = config[:database] || "hey_dude_configure_your_database" + # MSSQL support + options[:db_type] = config[:db_type] if config[:db_type] + options[:socket] = config[:socket] if config[:socket] + options[:charset] = config[:charset] if config[:charset] + options[:encoding] = config[:encoding] if config[:encoding] + options[:loggers] = [Rails.logger] + options end end end \ No newline at end of file diff --git a/lib/rails_sequel/version.rb b/lib/rails_sequel/version.rb index 94783a9..deecfea 100644 --- a/lib/rails_sequel/version.rb +++ b/lib/rails_sequel/version.rb @@ -2,8 +2,8 @@ module Rails module SequelConnection module Version MAJOR = 0 - MINOR = 0 - TINY = 2 + MINOR = 1 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/rails_sequel.gemspec b/rails_sequel.gemspec index 8433858..4d5828f 100644 --- a/rails_sequel.gemspec +++ b/rails_sequel.gemspec @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/lib/rails_sequel/version') Gem::Specification.new do |s| s.name = 'rails_sequel' - s.version = "0.1.0" + s.version = "0.1.2" s.date = '2009-01-14' s.summary = "Sequel plugin for Ruby on Rails" diff --git a/tasks/sequel.rake b/tasks/sequel.rake new file mode 100644 index 0000000..54b0e12 --- /dev/null +++ b/tasks/sequel.rake @@ -0,0 +1,17 @@ +# Usage: +# +# rake sequel:migrate +# rake sequel:migrate VERSION=0 +# rake sequel:migrate VERSION=3 +# +desc 'Sequel migration' +namespace :sequel do + task :migrate => :environment do + path = File.join(RAILS_ROOT, 'db', 'migrate') + if ENV['VERSION'] + Sequel::Migrator.apply(Sequel::Model.db, path, ENV['VERSION'].to_i) + else + Sequel::Migrator.apply(Sequel::Model.db, path) + end + end +end \ No newline at end of file