Class: GraphQL::FancyLoader::RankQueryGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/fancy_loader/rank_query_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(column:, partition_by:, table:, name_suffix: '_rank') ⇒ RankQueryGenerator

Returns a new instance of RankQueryGenerator.

Parameters:

  • column (Symbol)

    The table column to rank by

  • partition_by (Symbol)

    The find_by key for the table

  • table (Arel::Table)
  • name_suffix (String) (defaults to: '_rank')

    The suffix the be used for the column name



9
10
11
12
13
14
# File 'lib/graphql/fancy_loader/rank_query_generator.rb', line 9

def initialize(column:, partition_by:, table:, name_suffix: '_rank')
  @column = column
  @partition_by = partition_by
  @table = table
  @name_suffix = name_suffix
end

Instance Method Details

#arelObject

Our actual window function.

ROW_NUMBER() OVER (#{partition})


19
20
21
# File 'lib/graphql/fancy_loader/rank_query_generator.rb', line 19

def arel
  Arel::Nodes::NamedFunction.new('ROW_NUMBER', []).over(partition).as(name)
end