Sha256: 3121ddbc8b2c0dd8337297929e9f8075af44c667cf2ec679093637eda554336b

Contents?: true

Size: 1.88 KB

Versions: 25

Compression:

Stored size: 1.88 KB

Contents

require 'openbase'

module Sequel
  module OpenBase
    class Database < Sequel::Database
      set_adapter_scheme :openbase
      
      def connect
        OpenBase.new(
          opts[:database],
          opts[:host] || 'localhost',
          opts[:user],
          opts[:password]
        )
      end
      
      def disconnect
        # would this work?
        @pool.disconnect {|c| c.disconnect}
      end
    
      def dataset(opts = nil)
        OpenBase::Dataset.new(self, opts)
      end
    
      def execute(sql)
        @logger.info(sql) if @logger
        @pool.hold {|conn| conn.execute(sql)}
      end
      
      alias_method :do, :execute
    end
    
    class Dataset < Sequel::Dataset
      def literal(v)
        case v
        when Time
          literal(v.iso8601)
        else
          super
        end
      end

      def fetch_rows(sql, &block)
        @db.synchronize do
          result = @db.execute sql
          begin
            @columns = result.column_infos.map {|c| c.name.to_sym}
            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
      
      def array_tuples_fetch_rows(sql, &block)
        @db.synchronize do
          result = @db.execute sql
          begin
            @columns = result.column_infos.map {|c| c.name.to_sym}
            result.each do |r|
              r.keys = @columns
              yield r
            end
          ensure
            # cursor.close
          end
        end
        self
      end
      
      def insert(*values)
        @db.do insert_sql(*values)
      end
    
      def update(*args, &block)
        @db.do update_sql(*args, &block)
      end
    
      def delete(opts = nil)
        @db.do delete_sql(opts)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
sequel-0.4.4.2 lib/sequel/adapters/openbase.rb
sequel-0.5.0.1 lib/sequel/adapters/openbase.rb
sequel-0.4.5 lib/sequel/adapters/openbase.rb
sequel-0.5.0.2 lib/sequel/adapters/openbase.rb
sequel-0.5 lib/sequel/adapters/openbase.rb
sequel_core-1.0.10 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.2 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.1 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.3 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.0.1 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.8.1 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.4 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.4.1 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.5 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.8.2 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.6 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.7 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.9.1 lib/sequel_core/adapters/openbase.rb
sequel_core-1.0.8 lib/sequel_core/adapters/openbase.rb
sequel_core-1.1 lib/sequel_core/adapters/openbase.rb