Sha256: a0dac33648df23cc76150128511983691d1a29772991f7cbd67835d71d910086

Contents?: true

Size: 666 Bytes

Versions: 11

Compression:

Stored size: 666 Bytes

Contents

require 'mobility/backends/sequel/postgres_query_methods'
require "mobility/backends/sequel/query_methods"

Sequel.extension :pg_json, :pg_json_ops

module Mobility
  module Backends
    class Sequel::Jsonb::QueryMethods < Sequel::QueryMethods
      include PostgresQueryMethods

      def initialize(attributes, _)
        super

        define_query_methods("pg_jsonb")

        attributes.each do |attribute|
          define_method :"first_by_#{attribute}" do |value|
            where(::Sequel.pg_jsonb_op(attribute).contains({ Mobility.locale => value })).
              select_all(model.table_name).first
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mobility-0.3.6 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.5 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.4 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.3 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.2 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.1 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.3.0 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.2.3 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.2.2 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.2.1 lib/mobility/backends/sequel/jsonb/query_methods.rb
mobility-0.2.0 lib/mobility/backends/sequel/jsonb/query_methods.rb