module Pureapi::PostgresModel
Provide methods (override, polymorphic) for use data handling # => comfortable when use postgresql
Constants
- PERMIT_OPERATORS
- REFLECT_OPERATORS
Public Instance Methods
_self_search(only_params)
click to toggle source
Search by params of attributes of model
# File lib/pureapi/postgres_model.rb, line 59 def _self_search only_params criterias = self only_params.each do |filter| case filter[:o] when Operators::EQ[:id], Operators::IN[:id] criterias = criterias.where(filter[:f] => filter[:v]) when Operators::ISNIL[:id], Operators::ISNNIL[:id] criterias = criterias.where("\"#{self.table_name}\".\"#{filter[:f]}\" #{REFLECT_OPERATORS[filter[:o]]}") else criterias = criterias.where("\"#{self.table_name}\".\"#{filter[:f]}\" #{REFLECT_OPERATORS[filter[:o]]} ?", filter[:v]) end end return criterias.where({}) end
compconds(params = [])
click to toggle source
Comparsion operator conditions method Array params
contains hash = {f, o, v} :f is column name :o is comparsion operator :v is value
# File lib/pureapi/postgres_model.rb, line 44 def compconds(params = []) criterias = self params.each do |param| if param[:o] == COMPARISON_OPERATORS[:eq] criterias = criterias.where(param[:f] => param[:v]) else criterias = criterias.where("\"#{self.table_name}\".\"#{param[:f]}\" #{param[:o]} ?", param[:v]) end end return criterias.where({}) end