Module: HQ::GraphQL::FilterOperations

Included in:
HQ::GraphQL::Filters::Filter
Defined in:
lib/hq/graphql/filter_operations.rb

Defined Under Namespace

Classes: Operation

Constant Summary collapse

OPERATIONS =
[
  EQUAL = Operation.new(name: "EQUAL", arel: :eq),
  NOT_EQUAL = Operation.new(name: "NOT_EQUAL", arel: :not_eq, check_for_null: true),
  LIKE = Operation.new(name: "LIKE", arel: :matches, sanitize: ->(value) { "%#{ActiveRecord::Base.sanitize_sql_like(value)}%" }),
  NOT_LIKE = Operation.new(name: "NOT_LIKE", arel: :does_not_match, check_for_null: true, sanitize: ->(value) { "%#{ActiveRecord::Base.sanitize_sql_like(value)}%" }),
  GREATER_THAN = Operation.new(name: "GREATER_THAN", arel: :gt),
  LESS_THAN = Operation.new(name: "LESS_THAN", arel: :lt),
  WITH = Operation.new(
    name: "WITH",
    arel: ->(table:, column_name:, value:) do
      if value.casecmp("t") == 0 || value.casecmp("true") == 0
        table[column_name].not_eq(nil)
      else
        table[column_name].eq(nil)
      end
    end
  )
]