Sha256: 1c6936a6ce56c62b544efd794dcf958b189eacabbb73df3536e24d793c2232a3

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 KB

Contents

# require 'adapter_lib'

module Sequel
  module Adapter
    class Database < Sequel::Database
      set_adapter_scheme :adapter
      
      def connect
        AdapterDB.new(@opts[:database], @opts[:user], @opts[:password])
      end
      
      def disconnect
        @pool.disconnect {|c| c.disconnect}
      end
    
      def dataset(opts = nil)
        Adapter::Dataset.new(self, opts)
      end
      
      def execute(sql)
        @logger.info(sql) if @logger
        @pool.hold {|conn| conn.exec(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
          cursor = @db.execute sql
          begin
            @columns = cursor.get_col_names.map {|c| c.to_sym}
            while r = cursor.fetch
              row = {}
              r.each_with_index {|v, i| row[@columns[i]] = v}
              yield row
            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

12 entries across 12 versions & 1 rubygems

Version Path
sequel_core-1.0.10 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.8.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.8.2 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.8 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.9.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.2.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.5.0 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.5.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.3 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.2 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.4.0 lib/sequel_core/adapters/adapter_skeleton.rb