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_hstore.rb
  6. lib/sequel/extensions/pg_hstore_ops.rb
  7. lib/sequel/extensions/pg_inet_ops.rb
  8. lib/sequel/extensions/pg_json.rb
  9. lib/sequel/extensions/pg_json_ops.rb
  10. lib/sequel/extensions/pg_multirange.rb
  11. lib/sequel/extensions/pg_range.rb
  12. lib/sequel/extensions/pg_range_ops.rb
  13. lib/sequel/extensions/pg_row.rb
  14. lib/sequel/extensions/pg_row_ops.rb
  15. lib/sequel/extensions/sqlite_json_ops.rb
  16. lib/sequel/extensions/string_agg.rb
  17. 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
308 def hstore(v)
309   case v
310   when Postgres::HStore
311     v
312   when Hash
313     Postgres::HStore.new(v)
314   else
315     # May not be defined unless the pg_hstore_ops extension is used
316     hstore_op(v)
317   end
318 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
485 def pg_array(v, array_type=nil)
486   case v
487   when Postgres::PGArray
488     if array_type.nil? || v.array_type == array_type
489       v
490     else
491       Postgres::PGArray.new(v.to_a, array_type)
492     end
493   when Array
494     Postgres::PGArray.new(v, array_type)
495   else
496     # May not be defined unless the pg_array_ops extension is used
497     pg_array_op(v)
498   end
499 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
354 def pg_multirange(v, db_type)
355   case v
356   when Postgres::PGMultiRange
357     if v.db_type == db_type
358       v
359     else
360       Postgres::PGMultiRange.new(v, db_type)
361     end
362   when Array
363     Postgres::PGMultiRange.new(v, db_type)
364   else
365     # May not be defined unless the pg_range_ops extension is used
366     pg_range_op(v)
367   end
368 end
pg_range(v, db_type=nil)

Convert the object to a Postgres::PGRange.

[show source]
    # File lib/sequel/extensions/pg_range.rb
525 def pg_range(v, db_type=nil)
526   case v
527   when Postgres::PGRange
528     if db_type.nil? || v.db_type == db_type
529       v
530     else
531       Postgres::PGRange.new(v.begin, v.end, :exclude_begin=>v.exclude_begin?, :exclude_end=>v.exclude_end?, :db_type=>db_type)
532     end
533   when Range
534     Postgres::PGRange.from_range(v, db_type)
535   else
536     # May not be defined unless the pg_range_ops extension is used
537     pg_range_op(v)
538   end
539 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
549 def pg_row(expr)
550   case expr
551   when Array
552     Postgres::PGRow::ArrayRow.new(expr)
553   else
554     # Will only work if pg_row_ops extension is loaded
555     pg_row_op(expr)
556   end
557 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
sqlite_json_op(v)

Return the object wrapped in an SQLite::JSONOp.

[show source]
    # File lib/sequel/extensions/sqlite_json_ops.rb
222 def sqlite_json_op(v)
223   case v
224   when SQLite::JSONOp
225     v
226   else
227     SQLite::JSONOp.new(v)
228   end
229 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