class Datagrid::Drivers::Sequel

@!visibility private

Public Class Methods

match?(scope) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 6
def self.match?(scope)
  return false unless defined?(::Sequel)
  if scope.is_a?(Class)
    scope.ancestors.include?(::Sequel::Model)
  else
    scope.is_a?(::Sequel::Dataset)
  end
end

Public Instance Methods

append_column_queries(assets, columns) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 20
def append_column_queries(assets, columns)
  super
end
asc(scope, order) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 28
def asc(scope, order)
  scope.order(::Sequel.lit(order))
end
batch_each(scope, batch_size, &block) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 84
def batch_each(scope, batch_size, &block)
  if scope.opts[:limit]
    scope.each(&block)
  else
    scope.extension(:pagination).each_page(batch_size) do |page|
      page.each(&block)
    end
  end
end
can_preload?(scope, association) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 98
def can_preload?(scope, association)
  !! scope.model.association_reflection(association)
end
column_names(scope) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 56
def column_names(scope)
  scope.columns
end
contains(scope, field, value) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 60
def contains(scope, field, value)
  field = prefix_table_name(scope, field)
  scope.where(Sequel.like(field, "%#{value}%"))
end
default_cache_key(asset) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 80
def default_cache_key(asset)
  asset.id || raise(NotImplementedError)
end
default_order(scope, column_name) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 40
def default_order(scope, column_name)
  has_column?(scope, column_name) ?  ::Sequel.lit(prefix_table_name(scope, column_name)) : nil
end
default_preload(scope, value) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 94
def default_preload(scope, value)
  scope.eager(value)
end
desc(scope, order) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 32
def desc(scope, order)
  scope.order(::Sequel.desc(::Sequel.lit(order)))
end
greater_equal(scope, field, value) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 44
def greater_equal(scope, field, value)
  scope.where(::Sequel.lit("#{prefix_table_name(scope, field)} >= ?", value))
end
has_column?(scope, column_name) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 52
def has_column?(scope, column_name)
  scope.columns.include?(column_name.to_sym)
end
less_equal(scope, field, value) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 48
def less_equal(scope, field, value)
  scope.where(::Sequel.lit("#{prefix_table_name(scope, field)} <= ?", value))
end
normalized_column_type(scope, field) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 65
def normalized_column_type(scope, field)
  type = column_type(scope, field)
  return nil unless type
  {
    [:string, :blob, :time] => :string,
    [:integer, :primary_key] => :integer,
    [:float, :decimal] => :float,
    [:date] => :date,
    [:datetime] => :timestamp,
    [:boolean] => :boolean
  }.each do |keys, value|
    return value if keys.include?(type)
  end
end
reverse_order(scope) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 36
def reverse_order(scope)
  super
end
to_scope(scope) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 15
def to_scope(scope)
  return scope if scope.is_a?(::Sequel::Dataset)
  scope.where({})
end
where(scope, attribute, value) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 24
def where(scope, attribute, value)
  scope.where(attribute => value)
end

Protected Instance Methods

column_type(scope, field) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 109
def column_type(scope, field)
  has_column?(scope, field) ? to_scope(scope).row_proc.db_schema[field.to_sym][:type] : nil
end
prefix_table_name(scope, field) click to toggle source
# File lib/datagrid/drivers/sequel.rb, line 105
def prefix_table_name(scope, field)
  has_column?(scope, field) ?  [to_scope(scope).row_proc.table_name, field].join(".") : field
end