Sha256: 31ef2fefd9a7533181c9466a557bcafb0c8d2c47d73ccbaca5b60cb8e7a71fb2

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

require 'openbase'

module Sequel
  module OpenBase
    class Database < Sequel::Database
      set_adapter_scheme :openbase
      
      def connect(server)
        opts = server_opts(server)
        OpenBase.new(
          opts[:database],
          opts[:host] || 'localhost',
          opts[:user],
          opts[:password]
        )
      end
      
      def dataset(opts = nil)
        OpenBase::Dataset.new(self, opts)
      end
    
      def execute(sql, opts={})
        log_info(sql)
        synchronize(opts[:server]) do |conn|
          r = conn.execute(sql)
          yield(r) if block_given?
          r
        end
      end
      alias_method :do, :execute

      private

      def disconnect_connection(c)
        c.disconnect
      end
    end
    
    class Dataset < Sequel::Dataset
      def fetch_rows(sql)
        execute(sql) do |result|
          begin
            @columns = result.column_infos.map{|c| output_identifier(c.name)}
            result.each do |r|
              row = {}
              r.each_with_index {|v, i| row[@columns[i]] = v}
              yield row
            end
          ensure
            # result.close
          end
        end
        self
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
colincasey-sequel-2.10.2 lib/sequel_core/adapters/openbase.rb
colincasey-sequel-2.10.4 lib/sequel_core/adapters/openbase.rb
epugh-sequel-0.0.0 lib/sequel/adapters/openbase.rb
sequel-2.11.0 lib/sequel_core/adapters/openbase.rb
sequel-2.12.0 lib/sequel/adapters/openbase.rb
sequel-3.1.0 lib/sequel/adapters/openbase.rb
sequel-3.0.0 lib/sequel/adapters/openbase.rb