Sha256: d60dba1a505832c13a61ce72ca4ea534cc639ae0ec0f67b3163b76dd0cb73fe5

Contents?: true

Size: 643 Bytes

Versions: 2

Compression:

Stored size: 643 Bytes

Contents

require 'mobility/backend/sequel/postgres_query_methods'

Sequel.extension :pg_hstore, :pg_hstore_ops

module Mobility
  module Backend
    class Sequel::Hstore::QueryMethods < Sequel::QueryMethods
      include PostgresQueryMethods

      def initialize(attributes, **)
        super

        define_query_methods("hstore")

        attributes.each do |attribute|
          define_method :"first_by_#{attribute}" do |value|
            where(::Sequel.hstore(attribute.to_sym).contains(::Sequel.hstore({ Mobility.locale.to_s => 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/hstore/query_methods.rb
mobility-0.1.19 lib/mobility/backend/sequel/hstore/query_methods.rb