Sha256: a0367760b669d1d2e77f73d19bb323477f627e58d361500418569c41a11fc7a7

Contents?: true

Size: 772 Bytes

Versions: 159

Compression:

Stored size: 772 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: -> { HashWithIndifferentAccess.new }
    serialize :preferences, HashSerializer

    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

Version data entries

159 entries across 159 versions & 2 rubygems

Version Path
motor-admin-0.4.3 app/models/motor/query.rb
motor-admin-0.4.2 app/models/motor/query.rb
motor-admin-0.4.0 app/models/motor/query.rb
motor-admin-0.3.17 app/models/motor/query.rb
motor-admin-0.3.16 app/models/motor/query.rb
motor-admin-0.3.15 app/models/motor/query.rb
mafia-admin-0.3.18 app/models/motor/query.rb
mafia-admin-0.3.17 app/models/motor/query.rb
mafia-admin-0.3.16 app/models/motor/query.rb
mafia-admin-0.3.15 app/models/motor/query.rb
mafia-admin-0.3.14 app/models/motor/query.rb
motor-admin-0.3.14 app/models/motor/query.rb
motor-admin-0.3.13 app/models/motor/query.rb
motor-admin-0.3.12 app/models/motor/query.rb
motor-admin-0.3.11 app/models/motor/query.rb
motor-admin-0.3.10 app/models/motor/query.rb
motor-admin-0.3.9 app/models/motor/query.rb
motor-admin-0.3.8 app/models/motor/query.rb
motor-admin-0.3.7 app/models/motor/query.rb
motor-admin-0.3.6 app/models/motor/query.rb