module ROM::SQL::Postgres::Types

@api public

@api public

@api public

Constants

Array
ArrayRead
Box
Bytea
Circle
DateRange
HStore
IPAddress
Int4Range
Int8Range
JSON
JSONB
JSONNull
JSONRead
LTree

@see www.postgresql.org/docs/current/static/ltree.html

Line
LineSegment
Money
NumRange
Path
Point

The list of geometric data types supported by PostgreSQL @see www.postgresql.org/docs/current/static/datatype-geometric.html

Polygon
TsRange
TsTzRange
UUID
XML

Public Class Methods

Array(db_type, member_type = nil) click to toggle source

@api private

# File lib/rom/sql/extensions/postgres/types/array.rb, line 23
def self.Array(db_type, member_type = nil)
  array_types[db_type, member_type]
end
Type(name, type = yield) click to toggle source
# File lib/rom/sql/extensions/postgres/types.rb, line 13
def self.Type(name, type = yield)
  type.meta(db_type: name, database: 'postgres')
end
array_types() click to toggle source

@api private

# File lib/rom/sql/extensions/postgres/types/array.rb, line 18
def self.array_types
  @array_types ||= ArrayTypes.new(Postgres::Types::Array, Postgres::Types::ArrayRead)
end
range(name, read_type) click to toggle source

@api private

# File lib/rom/sql/extensions/postgres/types/range.rb, line 78
def self.range(name, read_type)
  Type(name) do
    type = SQL::Types.Nominal(Values::Range).constructor do |range|
      format('%s%s,%s%s',
             range.exclude_begin? ? :'(' : :'[',
             range.lower,
             range.upper,
             range.exclude_end? ? :')' : :']')
    end

    type.meta(read: read_type)
  end
end
range_read_type(name) click to toggle source

@api private

# File lib/rom/sql/extensions/postgres/types/range.rb, line 56
def self.range_read_type(name)
  SQL::Types.Constructor(Values::Range) do |value|
    pg_range =
      if value.is_a?(Sequel::Postgres::PGRange)
        value
      elsif value && value.respond_to?(:to_s)
        @range_parsers[name].(value.to_s)
      else
        value
      end

    Values::Range.new(
      pg_range.begin,
      pg_range.end,
      [pg_range.exclude_begin? ? :'(' : :'[',
       pg_range.exclude_end? ? :')' : :']']
      .join('').to_sym
    )
  end
end

Public Instance Methods

+(_type, expr, other) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 318
def +(_type, expr, other)
  other_value = case other
                when ROM::Types::Values::TreePath
                  other
                else
                  ROM::Types::Values::TreePath.new(other)
                end
  Attribute[LTree].meta(sql_expr: Sequel::SQL::StringExpression.new(:'||', expr, other_value.to_s))
end
ascendant(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 314
def ascendant(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
end
contain(_type, expr, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 259
def contain(_type, expr, value)
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contains(value))
end
contain_ancestor(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 268
def contain_ancestor(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
end
contain_any_ltextquery(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 264
def contain_any_ltextquery(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
end
contain_ascendant(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 309
def contain_ascendant(_type, expr, query)
  array = build_array_query(query, 'ltree')
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, array))
end
contain_descendant(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 272
def contain_descendant(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
end
contained_by(_type, expr, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 263
def contained_by(_type, expr, value)
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contained_by(value))
end
delete(_type, expr, *path) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 284
def delete(_type, expr, *path)
  sql_expr = path.size == 1 ? wrap(expr) - path : wrap(expr).delete_path(path)
  Attribute[JSONB].meta(sql_expr: sql_expr)
end
descendant(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 305
def descendant(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
end
find_ancestor(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 276
def find_ancestor(_type, expr, query)
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_ASCENDANT, expr, query))
end
find_descendant(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 280
def find_descendant(_type, expr, query)
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_DESCENDANT, expr, query))
end
has_all_keys(_type, expr, *keys) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 275
def has_all_keys(_type, expr, *keys)
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_all(keys))
end
has_any_key(_type, expr, *keys) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 271
def has_any_key(_type, expr, *keys)
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_any(keys))
end
has_key(_type, expr, key) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 267
def has_key(_type, expr, key)
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).has_key?(key))
end
match_any_lquery(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 284
def match_any_lquery(_type, expr, query)
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LQUERY, expr, query))
end
match_any_ltextquery(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 288
def match_any_ltextquery(_type, expr, query)
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LTEXTQUERY, expr, query))
end
match_ltextquery(_type, expr, query) click to toggle source
# File lib/rom/sql/extensions/postgres/types/ltree.rb, line 296
def match_ltextquery(_type, expr, query)
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
end
merge(_type, expr, value) click to toggle source
# File lib/rom/sql/extensions/postgres/types/json.rb, line 279
def merge(_type, expr, value)
  Attribute[JSONB].meta(sql_expr: wrap(expr).concat(value))
end