Sha256: e8096663a1130878dbc5001aaaa2f1989c03afcc551f0f89e8ad73735e4575cc

Contents?: true

Size: 616 Bytes

Versions: 2

Compression:

Stored size: 616 Bytes

Contents

require 'mobility/backend/sequel/postgres_query_methods'

Sequel.extension :pg_json, :pg_json_ops

module Mobility
  module Backend
    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

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.1.20 lib/mobility/backend/sequel/jsonb/query_methods.rb
mobility-0.1.19 lib/mobility/backend/sequel/jsonb/query_methods.rb