Class: QueryConsole::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/query_console/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/query_console/configuration.rb', line 24

def initialize
  @enabled_environments = ["development"]
  @max_rows = 500
  @timeout_ms = 3000
  @timeout_strategy = :database # :database (safer, PostgreSQL only) or :ruby (fallback, but can leave orphan queries)
  @authorize = nil # nil means deny by default
  @current_actor = -> (_controller) { "unknown" }
  @forbidden_keywords = %w[
    update delete insert drop alter create grant revoke truncate
    execute exec sp_executesql xp_ sp_ merge replace into
    shutdown backup restore transaction commit rollback
  ]
  @allowed_starts_with = %w[select with]
  
  # v0.2.0 additions
  @enable_explain = true
  @enable_explain_analyze = false # ANALYZE can be expensive, disabled by default
  @enable_dml = false # DML queries disabled by default for safety
  @schema_explorer = true
  @schema_cache_seconds = 60
  @schema_table_denylist = ["schema_migrations", "ar_internal_metadata"]
  @schema_allowlist = [] # empty means all tables allowed (except denylist)
  @enable_syntax_highlighting = true
  @enable_autocomplete = true
  @autocomplete_max_tables = 100
  @autocomplete_max_columns_per_table = 100
  @autocomplete_cache_ttl_seconds = 300 # 5 minutes
end

Instance Attribute Details

#allowed_starts_withObject

Returns the value of attribute allowed_starts_with.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def allowed_starts_with
  @allowed_starts_with
end

#authorizeObject

Returns the value of attribute authorize.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def authorize
  @authorize
end

#autocomplete_cache_ttl_secondsObject

Returns the value of attribute autocomplete_cache_ttl_seconds.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def autocomplete_cache_ttl_seconds
  @autocomplete_cache_ttl_seconds
end

#autocomplete_max_columns_per_tableObject

Returns the value of attribute autocomplete_max_columns_per_table.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def autocomplete_max_columns_per_table
  @autocomplete_max_columns_per_table
end

#autocomplete_max_tablesObject

Returns the value of attribute autocomplete_max_tables.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def autocomplete_max_tables
  @autocomplete_max_tables
end

#current_actorObject

Returns the value of attribute current_actor.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def current_actor
  @current_actor
end

#enable_autocompleteObject

Returns the value of attribute enable_autocomplete.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enable_autocomplete
  @enable_autocomplete
end

#enable_dmlObject

Returns the value of attribute enable_dml.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enable_dml
  @enable_dml
end

#enable_explainObject

Returns the value of attribute enable_explain.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enable_explain
  @enable_explain
end

#enable_explain_analyzeObject

Returns the value of attribute enable_explain_analyze.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enable_explain_analyze
  @enable_explain_analyze
end

#enable_syntax_highlightingObject

Returns the value of attribute enable_syntax_highlighting.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enable_syntax_highlighting
  @enable_syntax_highlighting
end

#enabled_environmentsObject

Returns the value of attribute enabled_environments.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def enabled_environments
  @enabled_environments
end

#forbidden_keywordsObject

Returns the value of attribute forbidden_keywords.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def forbidden_keywords
  @forbidden_keywords
end

#max_rowsObject

Returns the value of attribute max_rows.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def max_rows
  @max_rows
end

#schema_allowlistObject

Returns the value of attribute schema_allowlist.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def schema_allowlist
  @schema_allowlist
end

#schema_cache_secondsObject

Returns the value of attribute schema_cache_seconds.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def schema_cache_seconds
  @schema_cache_seconds
end

#schema_explorerObject

Returns the value of attribute schema_explorer.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def schema_explorer
  @schema_explorer
end

#schema_table_denylistObject

Returns the value of attribute schema_table_denylist.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def schema_table_denylist
  @schema_table_denylist
end

#timeout_msObject

Returns the value of attribute timeout_ms.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def timeout_ms
  @timeout_ms
end

#timeout_strategyObject

Returns the value of attribute timeout_strategy.



3
4
5
# File 'lib/query_console/configuration.rb', line 3

def timeout_strategy
  @timeout_strategy
end

Instance Method Details

#autocomplete_enabledObject

Validation: Autocomplete requires schema_explorer to be enabled



54
55
56
# File 'lib/query_console/configuration.rb', line 54

def autocomplete_enabled
  enable_autocomplete && schema_explorer
end