Skip to content
technorama edited this page Oct 7, 2015 · 1 revision

This defines the low level driver interface and namespaces. Most programs won't use this directly. Instead they will use higher level API's like ActiveRecord, Sequel, or DataMapper. The main consumers of this API are the higher level API's. I think long namespaces should not be a problem as descriptive names are more important.

Most common methods should be defined as abstract and have the same interface between drivers. Additional driver specific methods may be defined.

# The main interface
Db::Sql::Driver.new connection_url, options = nil

# Or use a specific driver directly
Db::Sql::Driver::Postgres.new connection_url, options = nil
Db::Sql::Driver::Mysql.new connection_url, options = nil
Db::Sql::Driver::Sequel.new connection_url, options = nil

The proposed namespaces:

module Db
  module Sql
    module Driver
      abstract class Base

      class Mysql < Base
      end
      class Postgres < Base
      end
      class Sqlite < Base
      end
    end

    module Error
      class Base < Exception
      end
      # ... all other types of common errors...
      # individual drivers may use them directly or subclass if necessary.
    end

    # transaction modules are loaded by the individual drivers depending on the db's capabilities.
    module Transaction
      # true nested transactions used by few db engines
      module Nested
      end

      # used by pg and mysql
      module SavePoint
      end
    end
  end
end
Clone this wiki locally