Class: QueryConsole::SqlLimiter

Inherits:
Object
  • Object
show all
Defined in:
app/services/query_console/sql_limiter.rb

Defined Under Namespace

Classes: LimitResult

Instance Method Summary collapse

Constructor Details

#initialize(sql, max_rows, config = QueryConsole.configuration) ⇒ SqlLimiter

Returns a new instance of SqlLimiter.



16
17
18
19
20
# File 'app/services/query_console/sql_limiter.rb', line 16

def initialize(sql, max_rows, config = QueryConsole.configuration)
  @sql = sql
  @max_rows = max_rows
  @config = config
end

Instance Method Details

#apply_limitObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/query_console/sql_limiter.rb', line 22

def apply_limit
  # Skip limiting for DML queries (INSERT, UPDATE, DELETE, MERGE)
  if is_dml_query?
    return LimitResult.new(sql: @sql, truncated: false)
  end
  
  # Check if query already has a LIMIT clause
  if sql_has_limit?
    LimitResult.new(sql: @sql, truncated: false)
  else
    wrapped_sql = wrap_with_limit(@sql, @max_rows)
    LimitResult.new(sql: wrapped_sql, truncated: true)
  end
end