Class: NPlusInsight::Query

Inherits:
Struct
  • Object
show all
Defined in:
lib/n_plus_insight/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cachedObject

Returns the value of attribute cached

Returns:

  • (Object)

    the current value of cached



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def cached
  @cached
end

#duration_msObject

Returns the value of attribute duration_ms

Returns:

  • (Object)

    the current value of duration_ms



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def duration_ms
  @duration_ms
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def location
  @location
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def name
  @name
end

#sqlObject

Returns the value of attribute sql

Returns:

  • (Object)

    the current value of sql



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def sql
  @sql
end

#tablesObject

Returns the value of attribute tables

Returns:

  • (Object)

    the current value of tables



2
3
4
# File 'lib/n_plus_insight/query.rb', line 2

def tables
  @tables
end

Instance Method Details

#binds_signatureObject



12
13
14
# File 'lib/n_plus_insight/query.rb', line 12

def binds_signature
  normalized_sql
end

#normalized_sqlObject



3
4
5
6
7
8
9
10
# File 'lib/n_plus_insight/query.rb', line 3

def normalized_sql
  sql.to_s
    .gsub(/'(?:[^']|'')*'/, "?")
    .gsub(/\b\d+(?:\.\d+)?\b/, "?")
    .gsub(/\bIN\s*\((?:\s*\?,?\s*)+\)/i, "IN (?)")
    .gsub(/\s+/, " ")
    .strip
end