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