Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Swift db drivers #526

Closed
wants to merge 12 commits into from

2 participants

@deepfryed

Update the Swift adapters for Sequel to use

https://github.com/deepfryed/swift-db-mysql
https://github.com/deepfryed/swift-db-postgres
https://github.com/deepfryed/swift-db-sqlite3

All three have been released to Rubygems and the corresponding specs all pass.

I have to look into all the pending tests for swift and try to get most of them to pass.

Thanks

@jeremyevans

Doesn't this add ::Sequel::Error instead of ::Swift::Error?

good catch, thanks

@jeremyevans
Owner

Briefly reviewing this now. Some notes:

We generally don't do $stderr.puts for explanatory error messages in exceptions. It should be obvious to users that if you get a LoadError when requiring swift/db/mysql, you need to install a library, and the documentation you added to opening_databases.rdoc should cover that.

You are removing ::SwiftError from Postgres::CONVERTED_EXCEPTIONS instead of replacing it with ::Swift::Error. What's the reasoning behind that?

Other than those things, this looks good, and I should be able to merge and test it tomorrow.

Thanks for the help!

@jeremyevans
Owner

Also, looking at the new drivers, it doesn't look like dbic++ is used anymore? Is that correct? If so, what's the status of dbic++ (I'm the OpenBSD maintainer of the dbic++ port)?

@deepfryed

We generally don't do $stderr.puts for explanatory error messages in exceptions.

removed the LoadError puts

"You are removing ::SwiftError from Postgres::CONVERTED_EXCEPTIONS instead of replacing it with ::Swift::Error. What's the reasoning behind that?"

I must have done it because Swift::Error required loading the swift/db/postgres first. I've just rearranged the require order and put that code back in sequel/adapters/swift/postgres

it doesn't look like dbic++ is used anymore?

Yes, it doesn't. Decoupling swift from the binary adapters was in the pipeline for a while and this rewrite lead to more cleaner and easier to maintain codebase.

what's the status of dbic++

I'm still maintaining dbic++ as it is still a library I use for writing c++ code.

@jeremyevans
Owner

Thanks for the changes and the info. I'll try to get this merged and tested tomorrow.

@jeremyevans jeremyevans closed this pull request from a commit
@jeremyevans 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++.
5068889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -8,3 +8,4 @@
*.rbc
*.swp
*.lock
+.rvmrc
View
6 doc/opening_databases.rdoc
@@ -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
View
20 lib/sequel/adapters/swift.rb
@@ -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')
@@ -13,18 +10,21 @@ module Swift
# Contains procs keyed on sub adapter type that extend the
# given database object so it supports the correct database type.
DATABASE_SETUP = {:postgres=>proc do |db|
+ require 'swift/db/postgres'
Sequel.ts_require 'adapters/swift/postgres'
db.extend(Sequel::Swift::Postgres::DatabaseMethods)
db.extend_datasets Sequel::Postgres::DatasetMethods
db.swift_class = ::Swift::DB::Postgres
end,
:mysql=>proc do |db|
+ require 'swift/db/mysql'
Sequel.ts_require 'adapters/swift/mysql'
db.extend(Sequel::Swift::MySQL::DatabaseMethods)
db.dataset_class = Sequel::Swift::MySQL::Dataset
db.swift_class = ::Swift::DB::Mysql
end,
:sqlite=>proc do |db|
+ require 'swift/db/sqlite3'
Sequel.ts_require 'adapters/swift/sqlite'
db.extend(Sequel::Swift::SQLite::DatabaseMethods)
db.dataset_class = Sequel::Swift::SQLite::Dataset
@@ -70,7 +70,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 +81,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 +94,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
View
2  lib/sequel/adapters/swift/postgres.rb
@@ -1,9 +1,9 @@
Sequel.require 'adapters/shared/postgres'
module Sequel
- Postgres::CONVERTED_EXCEPTIONS << ::SwiftError
module Swift
+ Postgres::CONVERTED_EXCEPTIONS << ::Swift::Error
# Adapter, Database, and Dataset support for accessing a PostgreSQL
# database via Swift.
module Postgres
View
2  lib/sequel/adapters/swift/sqlite.rb
@@ -25,7 +25,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
View
2  spec/adapters/mysql_spec.rb
@@ -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
+ cspecify "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"]
Something went wrong with that request. Please try again.