Sha256: 150cf164fcb269cfe4703e90770db6be2652ed57282633b8c97f318db840ad5d

Contents?: true

Size: 1.4 KB

Versions: 15

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

15 entries across 15 versions & 2 rubygems

Version Path
sequel-0.5.0.2 lib/sequel/adapters/adapter_skeleton.rb
sequel-0.4.4.2 lib/sequel/adapters/adapter_skeleton.rb
sequel-0.5.0.1 lib/sequel/adapters/adapter_skeleton.rb
sequel-0.4.5 lib/sequel/adapters/adapter_skeleton.rb
sequel-0.5 lib/sequel/adapters/adapter_skeleton.rb
sequel_core-1.0.3 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.2 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.0.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.4.1 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.6 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.7 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.5 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0.4 lib/sequel_core/adapters/adapter_skeleton.rb
sequel_core-1.0 lib/sequel_core/adapters/adapter_skeleton.rb