module Sequel::SQL::Builders

  1. lib/sequel/extensions/date_arithmetic.rb
  2. lib/sequel/extensions/pg_array.rb
  3. lib/sequel/extensions/pg_array_ops.rb
  4. lib/sequel/extensions/pg_hstore.rb
  5. lib/sequel/extensions/pg_hstore_ops.rb
  6. lib/sequel/extensions/pg_json.rb
  7. lib/sequel/extensions/pg_json_ops.rb
  8. lib/sequel/extensions/pg_range.rb
  9. lib/sequel/extensions/pg_range_ops.rb
  10. lib/sequel/extensions/pg_row.rb
  11. lib/sequel/extensions/pg_row_ops.rb
  12. show all
Parent: SQL

Public Instance methods

date_add (expr, interval)

Return a DateAdd expression, adding an interval to the date/timestamp expr.

[show source]
# File lib/sequel/extensions/date_arithmetic.rb, line 31
def date_add(expr, interval)
  DateAdd.new(expr, interval)
end
date_sub (expr, interval)

Return a DateAdd expression, adding the negative of the interval to the date/timestamp expr.

[show source]
# File lib/sequel/extensions/date_arithmetic.rb, line 37
def date_sub(expr, interval)
  interval = if interval.is_a?(Hash)
    h = {}
    interval.each{|k,v| h[k] = -v unless v.nil?}
    h
  else
    -interval
  end
  DateAdd.new(expr, interval)
end
hstore (v)

Return a Postgres::HStore proxy for the given hash.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 316
def hstore(v)
  case v
  when Postgres::HStore
    v
  when Hash
    Postgres::HStore.new(v)
  else
    # May not be defined unless the pg_hstore_ops extension is used
    hstore_op(v)
  end
end
hstore_op (v)

Return the object wrapped in an Postgres::HStoreOp.

[show source]
# File lib/sequel/extensions/pg_hstore_ops.rb, line 308
def hstore_op(v)
  case v
  when Postgres::HStoreOp
    v
  else
    Postgres::HStoreOp.new(v)
  end
end
pg_array (v, array_type=nil)

Return a Postgres::PGArray proxy for the given array and database array type.

[show source]
# File lib/sequel/extensions/pg_array.rb, line 581
def pg_array(v, array_type=nil)
  case v
  when Postgres::PGArray
    if array_type.nil? || v.array_type == array_type
      v
    else
      Postgres::PGArray.new(v.to_a, array_type)
    end
  when Array
    Postgres::PGArray.new(v, array_type)
  else
    # May not be defined unless the pg_array_ops extension is used
    pg_array_op(v)
  end
end
pg_array_op (v)

Return the object wrapped in an Postgres::ArrayOp.

[show source]
# File lib/sequel/extensions/pg_array_ops.rb, line 275
def pg_array_op(v)
  case v
  when Postgres::ArrayOp
    v
  else
    Postgres::ArrayOp.new(v)
  end
end
pg_json (v)

Wrap the array or hash in a Postgres::JSONArray or Postgres::JSONHash.

[show source]
# File lib/sequel/extensions/pg_json.rb, line 195
def pg_json(v)
  case v
  when Postgres::JSONArray, Postgres::JSONHash
    v
  when Array
    Postgres::JSONArray.new(v)
  when Hash
    Postgres::JSONHash.new(v)
  else
    Sequel.pg_json_op(v)
  end
end
pg_json_op (v)

Return the object wrapped in an Postgres::JSONOp.

[show source]
# File lib/sequel/extensions/pg_json_ops.rb, line 227
def pg_json_op(v)
  case v
  when Postgres::JSONOp
    v
  else
    Postgres::JSONOp.new(v)
  end
end
pg_range (v, db_type=nil)

Convert the object to a Postgres::PGRange.

[show source]
# File lib/sequel/extensions/pg_range.rb, line 501
def pg_range(v, db_type=nil)
  case v
  when Postgres::PGRange
    if db_type.nil? || v.db_type == db_type
      v
    else
      Postgres::PGRange.new(v.begin, v.end, :exclude_begin=>v.exclude_begin?, :exclude_end=>v.exclude_end?, :db_type=>db_type)
    end
  when Range
    Postgres::PGRange.from_range(v, db_type)
  else
    # May not be defined unless the pg_range_ops extension is used
    pg_range_op(v)
  end
end
pg_range_op (v)

Return the expression wrapped in the Postgres::RangeOp.

[show source]
# File lib/sequel/extensions/pg_range_ops.rb, line 128
def pg_range_op(v)
  case v
  when Postgres::RangeOp
    v
  else
    Postgres::RangeOp.new(v)
  end
end
pg_row (expr)

Wraps the expr array in an anonymous Postgres::PGRow::ArrayRow instance.

[show source]
# File lib/sequel/extensions/pg_row.rb, line 578
def pg_row(expr)
  case expr
  when Array
    Postgres::PGRow::ArrayRow.new(expr)
  else
    # Will only work if pg_row_ops extension is loaded
    pg_row_op(expr)
  end
end
pg_row_op (expr)

Return a PGRowOp wrapping the given expression.

[show source]
# File lib/sequel/extensions/pg_row_ops.rb, line 165
def pg_row_op(expr)
  Postgres::PGRowOp.wrap(expr)
end