Sha256: 8d73403edbe312dc50cbb47846371b069f6ee493d9a135d46d4c3919c28a5c7f

Contents?: true

Size: 950 Bytes

Versions: 26

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true

module Motor
  class Query < ::Motor::ApplicationRecord
    audited

    belongs_to :author, polymorphic: true, optional: true

    has_many :taggable_tags, as: :taggable, dependent: :destroy
    has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
    has_many :alerts, dependent: :destroy

    attribute :preferences, default: -> { ActiveSupport::HashWithIndifferentAccess.new }

    if Rails.version.to_f >= 7.1
      serialize :preferences, coder: HashSerializer
    else
      serialize :preferences, HashSerializer
    end

    scope :active, -> { where(deleted_at: nil) }

    def result(variables_hash = {})
      result = Motor::Queries::RunQuery.call!(self, variables_hash: variables_hash)
      column_names = result.columns.pluck(:name)

      result.data.map { |row| column_names.zip(row).to_h }
    end
    alias run result
  end
end

ActiveSupport.run_load_hooks(:motor_query, Motor::Query)

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
motor-admin-0.4.36 app/models/motor/query.rb
motor-admin-0.4.35 app/models/motor/query.rb
motor-admin-0.4.34 app/models/motor/query.rb
motor-admin-0.4.33 app/models/motor/query.rb
motor-admin-0.4.32 app/models/motor/query.rb
motor-admin-0.4.31 app/models/motor/query.rb
motor-admin-0.4.30 app/models/motor/query.rb
motor-admin-0.4.29 app/models/motor/query.rb
motor-admin-0.4.28 app/models/motor/query.rb
motor-admin-cstham8-0.4.35 app/models/motor/query.rb
motor-admin-cstham8-0.4.34 app/models/motor/query.rb
motor-admin-cstham8-0.4.33 app/models/motor/query.rb
motor-admin-cstham8-0.4.32 app/models/motor/query.rb
motor-admin-cstham8-0.4.31 app/models/motor/query.rb
motor-admin-cstham8-0.4.30 app/models/motor/query.rb
motor-admin-cstham8-0.4.29 app/models/motor/query.rb
motor-admin-cstham8-0.4.28 app/models/motor/query.rb
motor-admin-cstham8-0.4.27 app/models/motor/query.rb
motor-admin-0.4.27 app/models/motor/query.rb
motor-admin-unosquare-0.4.28 app/models/motor/query.rb