module Sequel::SQL::Builders

  1. lib/sequel/extensions/date_arithmetic.rb
  2. lib/sequel/extensions/is_distinct_from.rb
  3. lib/sequel/extensions/pg_array.rb
  4. lib/sequel/extensions/pg_array_ops.rb
  5. lib/sequel/extensions/pg_auto_parameterize.rb
  6. lib/sequel/extensions/pg_hstore.rb
  7. lib/sequel/extensions/pg_hstore_ops.rb
  8. lib/sequel/extensions/pg_inet_ops.rb
  9. lib/sequel/extensions/pg_json.rb
  10. lib/sequel/extensions/pg_json_ops.rb
  11. lib/sequel/extensions/pg_multirange.rb
  12. lib/sequel/extensions/pg_range.rb
  13. lib/sequel/extensions/pg_range_ops.rb
  14. lib/sequel/extensions/pg_row.rb
  15. lib/sequel/extensions/pg_row_ops.rb
  16. lib/sequel/extensions/sqlite_json_ops.rb
  17. lib/sequel/extensions/string_agg.rb
  18. show all

Public Instance methods

date_add(expr, interval, opts=OPTS)

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

:cast

Cast to the specified type instead of the default if casting

[show source]
   # File lib/sequel/extensions/date_arithmetic.rb
48 def date_add(expr, interval, opts=OPTS)
49   DateAdd.new(expr, interval, opts)
50 end
date_sub(expr, interval, opts=OPTS)

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

:cast

Cast to the specified type instead of the default if casting

[show source]
   # File lib/sequel/extensions/date_arithmetic.rb
56 def date_sub(expr, interval, opts=OPTS)
57   if defined?(ActiveSupport::Duration) && interval.is_a?(ActiveSupport::Duration)
58     interval = interval.parts
59   end
60   parts = {}
61   interval.each do |k,v|
62     case v
63     when nil
64       # ignore
65     when Numeric
66       parts[k] = -v
67     else
68       parts[k] = Sequel::SQL::NumericExpression.new(:*, v, -1)
69     end
70   end
71   DateAdd.new(expr, parts, opts)
72 end
hstore(v)

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

[show source]
    # File lib/sequel/extensions/pg_hstore.rb
313 def hstore(v)
314   case v
315   when Postgres::HStore
316     v
317   when Hash
318     Postgres::HStore.new(v)
319   else
320     # May not be defined unless the pg_hstore_ops extension is used
321     hstore_op(v)
322   end
323 end
hstore_op(v)

Return the object wrapped in an Postgres::HStoreOp.

[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
380 def hstore_op(v)
381   case v
382   when Postgres::HStoreOp
383     v
384   else
385     Postgres::HStoreOp.new(v)
386   end
387 end
is_distinct_from(lhs, rhs)

Return a IsDistinctFrom expression object, using the IS DISTINCT FROM operator with the given left hand side and right hand side.

[show source]
   # File lib/sequel/extensions/is_distinct_from.rb
37 def is_distinct_from(lhs, rhs)
38   BooleanExpression.new(:NOOP, IsDistinctFrom.new(lhs, rhs))
39 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
514 def pg_array(v, array_type=nil)
515   case v
516   when Postgres::PGArray
517     if array_type.nil? || v.array_type == array_type
518       v
519     else
520       Postgres::PGArray.new(v.to_a, array_type)
521     end
522   when Array
523     Postgres::PGArray.new(v, array_type)
524   else
525     # May not be defined unless the pg_array_ops extension is used
526     pg_array_op(v)
527   end
528 end
pg_array_op(v)

Return the object wrapped in an Postgres::ArrayOp.

[show source]
    # File lib/sequel/extensions/pg_array_ops.rb
303 def pg_array_op(v)
304   case v
305   when Postgres::ArrayOp
306     v
307   else
308     Postgres::ArrayOp.new(v)
309   end
310 end
pg_inet_op(v)

Return the expression wrapped in the Postgres::InetOp.

[show source]
    # File lib/sequel/extensions/pg_inet_ops.rb
171 def pg_inet_op(v)
172   case v
173   when Postgres::InetOp
174     v
175   else
176     Postgres::InetOp.new(v)
177   end
178 end
pg_json(v)

Wrap the array or hash in a Postgres::JSONArray or Postgres::JSONHash. Also handles Postgres::JSONObject and JSONBObjects. For other objects, calls Sequel.pg_json_op (which is defined by the pg_json_ops extension).

[show source]
    # File lib/sequel/extensions/pg_json.rb
522 def pg_json(v)
523   case v
524   when Postgres::JSONObject
525     v
526   when Array
527     Postgres::JSONArray.new(v)
528   when Hash
529     Postgres::JSONHash.new(v)
530   when Postgres::JSONBObject
531     v = v.__getobj__
532     Postgres::JSONDatabaseMethods.json_primitive_wrapper(v).new(v)
533   else
534     Sequel.pg_json_op(v)
535   end
536 end
pg_json_op(v)

Return the object wrapped in an Postgres::JSONOp.

[show source]
    # File lib/sequel/extensions/pg_json_ops.rb
761 def pg_json_op(v)
762   case v
763   when Postgres::JSONOp
764     v
765   else
766     Postgres::JSONOp.new(v)
767   end
768 end
pg_json_wrap(v)

Wraps Ruby array, hash, string, integer, float, true, false, and nil values with the appropriate JSON wrapper. Raises an exception for other types.

[show source]
    # File lib/sequel/extensions/pg_json.rb
541 def pg_json_wrap(v)
542   case v
543   when *Postgres::JSON_WRAP_CLASSES
544     Postgres::JSONDatabaseMethods.json_primitive_wrapper(v).new(v)
545   else
546     raise Error, "invalid value passed to Sequel.pg_json_wrap: #{v.inspect}"
547   end
548 end
pg_jsonb(v)

Wrap the array or hash in a Postgres::JSONBArray or Postgres::JSONBHash. Also handles Postgres::JSONObject and JSONBObjects. For other objects, calls Sequel.pg_json_op (which is defined by the pg_json_ops extension).

[show source]
    # File lib/sequel/extensions/pg_json.rb
554 def pg_jsonb(v)
555   case v
556   when Postgres::JSONBObject
557     v
558   when Array
559     Postgres::JSONBArray.new(v)
560   when Hash
561     Postgres::JSONBHash.new(v)
562   when Postgres::JSONObject
563     v = v.__getobj__
564     Postgres::JSONDatabaseMethods.jsonb_primitive_wrapper(v).new(v)
565   else
566     Sequel.pg_jsonb_op(v)
567   end
568 end
pg_jsonb_op(v)

Return the object wrapped in an Postgres::JSONBOp.

[show source]
    # File lib/sequel/extensions/pg_json_ops.rb
771 def pg_jsonb_op(v)
772   case v
773   when Postgres::JSONBOp
774     v
775   else
776     Postgres::JSONBOp.new(v)
777   end
778 end
pg_jsonb_wrap(v)

Wraps Ruby array, hash, string, integer, float, true, false, and nil values with the appropriate JSONB wrapper. Raises an exception for other types.

[show source]
    # File lib/sequel/extensions/pg_json.rb
573 def pg_jsonb_wrap(v)
574   case v
575   when *Postgres::JSON_WRAP_CLASSES
576     Postgres::JSONDatabaseMethods.jsonb_primitive_wrapper(v).new(v)
577   else
578     raise Error, "invalid value passed to Sequel.pg_jsonb_wrap: #{v.inspect}"
579   end
580 end
pg_multirange(v, db_type)

Convert the object to a Postgres::PGMultiRange.

[show source]
    # File lib/sequel/extensions/pg_multirange.rb
349 def pg_multirange(v, db_type)
350   case v
351   when Postgres::PGMultiRange
352     if v.db_type == db_type
353       v
354     else
355       Postgres::PGMultiRange.new(v, db_type)
356     end
357   when Array
358     Postgres::PGMultiRange.new(v, db_type)
359   else
360     # May not be defined unless the pg_range_ops extension is used
361     pg_range_op(v)
362   end
363 end
pg_range(v, db_type=nil)

Convert the object to a Postgres::PGRange.

[show source]
    # File lib/sequel/extensions/pg_range.rb
520 def pg_range(v, db_type=nil)
521   case v
522   when Postgres::PGRange
523     if db_type.nil? || v.db_type == db_type
524       v
525     else
526       Postgres::PGRange.new(v.begin, v.end, :exclude_begin=>v.exclude_begin?, :exclude_end=>v.exclude_end?, :db_type=>db_type)
527     end
528   when Range
529     Postgres::PGRange.from_range(v, db_type)
530   else
531     # May not be defined unless the pg_range_ops extension is used
532     pg_range_op(v)
533   end
534 end
pg_range_op(v)

Return the expression wrapped in the Postgres::RangeOp.

[show source]
    # File lib/sequel/extensions/pg_range_ops.rb
162 def pg_range_op(v)
163   case v
164   when Postgres::RangeOp
165     v
166   else
167     Postgres::RangeOp.new(v)
168   end
169 end
pg_row(expr)

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

[show source]
    # File lib/sequel/extensions/pg_row.rb
550 def pg_row(expr)
551   case expr
552   when Array
553     Postgres::PGRow::ArrayRow.new(expr)
554   else
555     # Will only work if pg_row_ops extension is loaded
556     pg_row_op(expr)
557   end
558 end
pg_row_op(expr)

Return a PGRowOp wrapping the given expression.

[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
189 def pg_row_op(expr)
190   Postgres::PGRowOp.wrap(expr)
191 end
skip_pg_auto_param(v)

Skip auto parameterization for the given object when building queries.

[show source]
    # File lib/sequel/extensions/pg_auto_parameterize.rb
503 def skip_pg_auto_param(v)
504   Postgres::AutoParameterize::SkipAutoParam.new(v)
505 end
sqlite_json_op(v)

Return the object wrapped in an SQLite::JSONOp.

[show source]
    # File lib/sequel/extensions/sqlite_json_ops.rb
270 def sqlite_json_op(v)
271   case v
272   when SQLite::JSONOp
273     v
274   else
275     SQLite::JSONOp.new(v)
276   end
277 end
sqlite_jsonb_op(v)

Return the object wrapped in an SQLite::JSONBOp.

[show source]
    # File lib/sequel/extensions/sqlite_json_ops.rb
280 def sqlite_jsonb_op(v)
281   case v
282   when SQLite::JSONBOp
283     v
284   else
285     SQLite::JSONBOp.new(v)
286   end
287 end
string_agg(*a)

Return a StringAgg expression for an aggregate string concatentation.

[show source]
   # File lib/sequel/extensions/string_agg.rb
65 def string_agg(*a)
66   StringAgg.new(*a)
67 end