module ROM::SQL::Postgres::Types::LTreeMethods

@!parse

class SQL::Attribute
  # @!method match(value)
  #   Check whether the LTree match a lquery value
  #   Translates to the ~ operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.match('Bottom.Cities') }
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method match_any(value)
  #   Check whether the LTree match any of the lquery values
  #   Translates to the ? operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.match_any(['Bottom', 'Bottom.Cities.*']) }
  #     people.select(:name).where { ltree_tags.match_any('Bottom,Bottom.Cities.*') }
  #
  #   @param [Array,String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method match_ltextquery(value)
  #   Check whether the LTree match a ltextquery
  #   Translates to the @ operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.match_ltextquery('Countries & Brasil') }
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method contain_descendant(value)
  #   Check whether the LTree is a descendant of the LTree values
  #   Translates to the <@ operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.contain_descendant(['Bottom.Cities']) }
  #     people.select(:name).where { ltree_tags.contain_descendant('Bottom.Cities, Bottom.Parks') }
  #
  #   @param [Array<String>, String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method descendant(value)
  #   Check whether the LTree is a descendant of the LTree value
  #   Translates to the <@ operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.descendant('Bottom.Cities') }
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method contain_ascendant(value)
  #   Check whether the LTree is a ascendant of the LTree values
  #   Translates to the @> operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.contain_ascendant(['Bottom.Cities']) }
  #     people.select(:name).where { ltree_tags.contain_ascendant('Bottom.Cities, Bottom.Parks') }
  #
  #   @param [Array<String>, String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method ascendant(value)
  #   Check whether the LTree is a ascendant of the LTree value
  #   Translates to the @> operator
  #
  #   @example
  #     people.select(:name).where { ltree_tags.ascendant('Bottom.Cities') }
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method +(value)
  #   Concatenate two LTree values
  #   Translates to ||
  #
  #   @example
  #     people.select { (ltree_tags + ROM::Types::Values::TreePath.new('Moscu')).as(:ltree_tags) }.where { name.is('Jade Doe') }
  #     people.select { (ltree_tags + 'Moscu').as(:ltree_tags) }.where { name.is('Jade Doe') }
  #
  #   @param [LTree, String] keys
  #
  #   @return [SQL::Attribute<Types::LTree>]
  #
  #   @api public

  # @!method contain_any_ltextquery(value)
  #   Does LTree array contain any path matching ltxtquery
  #   Translates to @
  #
  #   @example
  #     people.select(:name).where { parents_tags.contain_any_ltextquery('Parks')}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::Bool>]
  #
  #   @api public

  # @!method contain_ancestor(value)
  #   Does LTree array contain an ancestor of ltree
  #   Translates to @>
  #
  #   @example
  #     people.select(:name).where { parents_tags.contain_ancestor('Top.Building.EmpireState.381')}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::Bool>]
  #
  #   @api public

  # @!method contain_descendant(value)
  #   Does LTree array contain an descendant of ltree
  #   Translates to <@
  #
  #   @example
  #     people.select(:name).where { parents_tags.contain_descendant('Top.Building.EmpireState.381')}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::Bool>]
  #
  #   @api public

  # @!method find_ancestor(value)
  #   Return first LTree array entry that is an ancestor of ltree, NULL if none
  #   Translates to ?@>
  #
  #   @example
  #     people.select(:name).where { parents_tags.find_ancestor('Left.Parks').not(nil)}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::LTree>]
  #
  #   @api public

  # @!method find_descendant(value)
  #   Return first LTree array entry that is an descendant of ltree, NULL if none
  #   Translates to ?<@
  #
  #   @example
  #     people.select(:name).where { parents_tags.find_descendant('Left.Parks').not(nil)}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::LTree>]
  #
  #   @api public

  # @!method match_any_lquery(value)
  #   Return first LTree array entry that matches lquery, NULL if none
  #   Translates to ?~
  #
  #   @example
  #     people.select(:name).where { parents_tags.match_any_lquery('Right.*').not(nil)}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::LTree>]
  #
  #   @api public

  # @!method match_any_ltextquery(value)
  #   Return first LTree array entry that matches ltextquery, NULL if none
  #   Translates to ?@
  #
  #   @example
  #     people.select(:name).where { parents_tags.match_any_ltextquery('EmpireState').not(nil)}
  #
  #   @param [String] value
  #
  #   @return [SQL::Attribute<Types::PG::LTree>]
  #
  #   @api public

end

Constants

ASCENDANT
DESCENDANT
FIND_ASCENDANT
FIND_DESCENDANT
MATCH_ANY
MATCH_ANY_LQUERY
MATCH_ANY_LTEXTQUERY
MATCH_LTEXTQUERY

Public Instance Methods

match(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 236
def match(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'~', expr, query))
end
match_any(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 240
def match_any(_type, expr, query)
  array = build_array_query(query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(MATCH_ANY, expr, array))
end

Private Instance Methods

build_array_query(query, array_type = 'lquery') click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 251
def build_array_query(query, array_type = 'lquery')
  case query
  when ::Array
    ROM::SQL::Types::PG::Array(array_type)[query]
  when ::String
    ROM::SQL::Types::PG::Array(array_type)[query.split(',')]
  end
end
custom_operator_expr(string, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 247
def custom_operator_expr(string, expr, query)
  Sequel::SQL::PlaceholderLiteralString.new(string, [expr, query])
end