module ROM::SQL::Postgres::Types::ArrayMethods

@!parse

class SQL::Attribute
  # @!method contain(other)
  #   Check whether the array includes another array
  #   Translates to the @> operator
  #
  #   @param [Array] other
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method get(idx)
  #   Get element by index (PG uses 1-based indexing)
  #
  #   @param [Integer] idx
  #
  #   @return [SQL::Attribute]
  #
  #   @api public

  # @!method any(value)
  #   Check whether the array includes a value
  #   Translates to the ANY operator
  #
  #   @param [Object] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method contained_by(other)
  #   Check whether the array is contained by another array
  #   Translates to the <@ operator
  #
  #   @param [Array] other
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method length
  #   Return array size
  #
  #   @return [SQL::Attribute<Types::Integer>]
  #
  #   @api public

  # @!method overlaps(other)
  #   Check whether the arrays have common values
  #   Translates to &&
  #
  #   @param [Array] other
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method remove_value(value)
  #   Remove elements by value
  #
  #   @param [Object] value
  #
  #   @return [SQL::Attribute<Types::PG::Array>]
  #
  #   @api public

  # @!method join(delimiter, null_repr)
  #   Convert the array to a string by joining
  #   values with a delimiter (empty stirng by default)
  #   and optional filler for NULL values
  #   Translates to an `array_to_string` call
  #
  #   @param [Object] delimiter
  #   @param [Object] null_repr
  #
  #   @return [SQL::Attribute<Types::String>]
  #
  #   @api public

  # @!method +(other)
  #   Concatenate two arrays
  #
  #   @param [Array] other
  #
  #   @return [SQL::Attribute<Types::PG::Array>]
  #
  #   @api public
end

Public Instance Methods

+(type, expr, other) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 149
def +(type, expr, other)
  Attribute[type].meta(sql_expr: expr.pg_array.concat(other))
end
any(_type, expr, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 125
def any(_type, expr, value)
  Attribute[SQL::Types::Bool].meta(sql_expr: { value => expr.pg_array.any })
end
contain(type, expr, other) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 117
def contain(type, expr, other)
  Attribute[SQL::Types::Bool].meta(sql_expr: expr.pg_array.contains(type[other]))
end
contained_by(type, expr, other) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 129
def contained_by(type, expr, other)
  Attribute[SQL::Types::Bool].meta(sql_expr: expr.pg_array.contained_by(type[other]))
end
get(type, expr, idx) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 121
def get(type, expr, idx)
  Attribute[type].meta(sql_expr: expr.pg_array[idx])
end
join(_type, expr, delimiter = '', null = nil) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 145
def join(_type, expr, delimiter = '', null = nil)
  Attribute[SQL::Types::String].meta(sql_expr: expr.pg_array.join(delimiter, null))
end
length(_type, expr) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 133
def length(_type, expr)
  Attribute[SQL::Types::Integer].meta(sql_expr: expr.pg_array.length)
end
overlaps(type, expr, other_array) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 137
def overlaps(type, expr, other_array)
  Attribute[SQL::Types::Bool].meta(sql_expr: expr.pg_array.overlaps(type[other_array]))
end
remove_value(type, expr, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 141
def remove_value(type, expr, value)
  Attribute[type].meta(sql_expr: expr.pg_array.remove(cast(type, value)))
end

Private Instance Methods

cast(type, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/array.rb, line 155
def cast(type, value)
  Sequel.cast(value, type.meta[:type])
end