Permalink
Browse files

The swift adapters now require swift-db-* instead of swift itself (Fi…

…xes #526)

This is a squashed commit of Pull Request 526, along with some
local changes by me, including:

* Using :pass instead of :password so that connections that require
  passwords work.

* Requiring the swift-db adapter instead the subadapter instead
  of the main adapter proc.

* Adding appropriate guards to the specs.  Currently, hstore
  ? operators are broken on swift/postgres just like on do/postgres.
  Also, swift/sqlite is not completely stable, so add guards for
  the specs that cause it to crash (see
  deepfryed/swift-db-sqlite3#1 for details).

One good thing about this change is that with the swift-db-*
adapters, you only need to install the related gem, you don't need
to install dbic++.
  • Loading branch information...
1 parent 246fc41 commit 50688894ff612a915914afc5b9d1f99c9a6ba138 @jeremyevans committed Jul 26, 2012
View
@@ -8,3 +8,4 @@
*.rbc
*.swp
*.lock
+.rvmrc
View
@@ -1,5 +1,7 @@
=== HEAD
+* The swift adapters now require swift-db-* instead of swift itself (deepfryed, jeremyevans) (#526)
+
* Add :textsize option to tinytds adapter to override the default TEXTSIZE (jeremyevans, wardrop) (#525)
* Support an output identifier method in the swift adapter (jeremyevans)
@@ -387,6 +387,12 @@ swift is a ruby 1.9 only library, so you'll need to be running ruby 1.9. It
can connect to SQLite, MySQL, and PostgreSQL, and you must specify which
database using the db_type option.
+You need to install one of the swift db adapters
+
+* swift-db-sqlite3
+* swift-db-mysql
+* swift-db-postgres
+
Examples:
swift:///?database=:memory:&db_type=sqlite
@@ -1,11 +1,8 @@
-require 'swift'
-
module Sequel
- # Module holding the Swift support for Sequel. Swift is a
- # ruby front-end for dbic++, a fast database access library
- # written in C++.
+ # Module holding the Swift DB support for Sequel. Swift DB is a
+ # collection of drivers used in Swift ORM.
#
- # The Swift adapter currently supports PostgreSQL and MySQL:
+ # The Swift adapter currently supports PostgreSQL, MySQL and SQLite3
#
# Sequel.connect('swift://user:password@host/database?db_type=postgres')
# Sequel.connect('swift://user:password@host/database?db_type=mysql')
@@ -60,7 +57,9 @@ def initialize(opts)
# Create an instance of swift_class for the given options.
def connect(server)
- setup_connection(swift_class.new(server_opts(server)))
+ opts = server_opts(server)
+ opts[:pass] = opts[:password]
+ setup_connection(swift_class.new(opts))
end
# Execute the given SQL, yielding a Swift::Result if a block is given.
@@ -70,7 +69,7 @@ def execute(sql, opts={})
res = log_yield(sql){conn.execute(sql)}
yield res if block_given?
nil
- rescue SwiftError => e
+ rescue ::Swift::Error => e
raise_error(e)
end
end
@@ -81,8 +80,8 @@ def execute(sql, opts={})
def execute_dui(sql, opts={})
synchronize(opts[:server]) do |conn|
begin
- log_yield(sql){conn.execute(sql).rows}
- rescue SwiftError => e
+ log_yield(sql){conn.execute(sql).affected_rows}
+ rescue ::Swift::Error => e
raise_error(e)
end
end
@@ -94,7 +93,7 @@ def execute_insert(sql, opts={})
synchronize(opts[:server]) do |conn|
begin
log_yield(sql){conn.execute(sql).insert_id}
- rescue SwiftError => e
+ rescue ::Swift::Error => e
raise_error(e)
end
end
@@ -1,3 +1,4 @@
+require 'swift/db/mysql'
Sequel.require 'adapters/shared/mysql'
module Sequel
@@ -1,7 +1,8 @@
+require 'swift/db/postgres'
Sequel.require 'adapters/shared/postgres'
module Sequel
- Postgres::CONVERTED_EXCEPTIONS << ::SwiftError
+ Postgres::CONVERTED_EXCEPTIONS << ::Swift::Error
module Swift
# Adapter, Database, and Dataset support for accessing a PostgreSQL
@@ -1,3 +1,4 @@
+require 'swift/db/sqlite3'
Sequel.require 'adapters/shared/sqlite'
module Sequel
@@ -25,7 +26,7 @@ class Dataset < Swift::Dataset
# Use Swift's escape method for quoting.
def literal_string_append(sql, s)
- sql << db.synchronize{|c| c.escape(s)}
+ sql << APOS << db.synchronize{|c| c.escape(s)} << APOS
end
end
end
@@ -81,7 +81,7 @@ def logger.method_missing(m, msg)
@db.schema(:dolls).map{|k, v| v[:auto_increment]}.should == [nil, nil, true]
end
- cspecify "should support collate with various other column options", :swift do
+ specify "should support collate with various other column options" do
@db.create_table!(:dolls){ String :name, :size=>128, :collate=>:utf8_bin, :default=>'foo', :null=>false, :unique=>true}
@db[:dolls].insert
@db[:dolls].select_map(:name).should == ["foo"]
@@ -1811,8 +1811,8 @@ def left_item_id
@ds.get(h2.merge(h3).keys.pg_array.length).should == 2
@ds.get(h1.merge(h3).keys.pg_array.length).should == 3
- unless @db.adapter_scheme == :do
- # Broken DataObjects thinks operators with ? represent placeholders
+ unless [:do, :swift].include?(@db.adapter_scheme)
+ # Broken DataObjects and Swift thinks operators with ? represent placeholders
@ds.get(h1.contain_all(Sequel.pg_array(%w'a c'))).should == true
@ds.get(h1.contain_all(Sequel.pg_array(%w'a d'))).should == false
@@ -1836,7 +1836,7 @@ def left_item_id
@ds.from(Sequel.hstore('a'=>'b', 'c'=>nil).op.each).order(:key).all.should == [{:key=>'a', :value=>'b'}, {:key=>'c', :value=>nil}]
- unless @db.adapter_scheme == :do
+ unless [:do, :swift].include?(@db.adapter_scheme)
@ds.get(h1.has_key?('c')).should == true
@ds.get(h1.include?('c')).should == true
@ds.get(h1.key?('c')).should == true
@@ -783,13 +783,13 @@
@db.drop_table?(:imp)
end
- specify "should return primary key values " do
+ cspecify "should return primary key values", [:swift, :sqlite] do
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key).should == [1, 2, 3]
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key).should == [4, 5, 6]
@ds.order(:id).map([:id, :i]).should == [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60]]
end
- specify "should return primary key values when :slice is used" do
+ cspecify "should return primary key values when :slice is used", [:swift, :sqlite] do
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key, :slice=>2).should == [1, 2, 3]
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key, :slice=>2).should == [4, 5, 6]
@ds.order(:id).map([:id, :i]).should == [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60]]
@@ -322,7 +322,7 @@ def self_join(c)
c.exclude(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.should == %w'3'
end
- specify "should handle extreme case with 5 join tables" do
+ cspecify "should handle extreme case with 5 join tables", [:swift, :sqlite] do
Artist.many_through_many :related_albums, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id], [:artists, :id, :id], [:albums_artists, :artist_id, :album_id]], :class=>Album, :distinct=>true
@db[:albums_artists].delete
@album1.add_artist(@artist1)
@@ -1265,7 +1265,7 @@ class ::Tag < Sequel::Model
@db.drop_table?(:pages)
end
- it "should return rows in order of position" do
+ cspecify "should return rows in order of position", [:swift, :sqlite] do
@c.map(:name).should == %w[ Hm Ps Au P1 P2 P3 ]
end
@@ -1286,7 +1286,7 @@ class ::Tag < Sequel::Model
@c[:name => "P3"].next.should == nil
end
- it "should define move_to" do
+ cspecify "should define move_to", [:swift, :sqlite] do
@c[:name => "P2"].move_to(1)
@c.map(:name).should == %w[ Hm Ps Au P2 P1 P3 ]
@@ -1297,15 +1297,15 @@ class ::Tag < Sequel::Model
proc { @c[:name => "P2"].move_to(10) }.should raise_error(Sequel::Error)
end
- it "should define move_to_top and move_to_bottom" do
+ cspecify "should define move_to_top and move_to_bottom", [:swift, :sqlite] do
@c[:name => "Au"].move_to_top
@c.map(:name).should == %w[ Hm Au Ps P1 P2 P3 ]
@c[:name => "Au"].move_to_bottom
@c.map(:name).should == %w[ Hm Ps Au P1 P2 P3 ]
end
- it "should define move_up and move_down" do
+ cspecify "should define move_up and move_down", [:swift, :sqlite] do
@c[:name => "P2"].move_up
@c.map(:name).should == %w[ Hm Ps Au P2 P1 P3 ]
@@ -252,7 +252,7 @@
@ds.columns!.should == [:number]
end
- specify "should create tables from select statements correctly" do
+ cspecify "should create tables from select statements correctly", [:swift, :sqlite] do
@db.create_table!(:items){Integer :number}
@ds.insert([10])
@db.create_table(:items2, :as=>@db[:items])

0 comments on commit 5068889

Please sign in to comment.