Class: SqlGenius::Configuration
- Inherits:
-
Object
- Object
- SqlGenius::Configuration
- Defined in:
- lib/sql_genius/configuration.rb
Instance Attribute Summary collapse
-
#ai_api_key ⇒ Object
Returns the value of attribute ai_api_key.
-
#ai_auth_style ⇒ Object
AI auth style: :bearer (OpenAI, Ollama Cloud) or :api_key (Azure OpenAI).
-
#ai_client ⇒ Object
AI configuration — set to nil to disable AI features entirely.
-
#ai_endpoint ⇒ Object
Returns the value of attribute ai_endpoint.
-
#ai_model ⇒ Object
AI model name to pass in the request body (e.g. “gpt-4o”, “gpt-3.5-turbo”).
-
#ai_system_context ⇒ Object
Custom system prompt prepended to AI suggestions.
-
#audit_logger ⇒ Object
Logger instance for audit logging.
-
#authenticate ⇒ Object
Proc that receives the controller instance and returns true if the user is authorized.
-
#base_controller ⇒ Object
Base controller class for the engine to inherit from.
-
#blocked_tables ⇒ Object
Tables that must never be queried (auth, sessions, internal Rails tables).
-
#default_columns ⇒ Object
Default columns to check in the visual builder, keyed by table name.
-
#default_row_limit ⇒ Object
Default row limit when none is specified.
-
#featured_tables ⇒ Object
Tables to feature in the visual builder dropdown (array of strings).
-
#masked_column_patterns ⇒ Object
Column name patterns to mask with [REDACTED] in query results.
-
#max_row_limit ⇒ Object
Maximum rows a single query can return.
-
#min_unused_index_scans ⇒ Object
Maximum scan count for an index to still be considered “unused” by the Unused Indexes dashboard.
-
#query_timeout_ms ⇒ Object
Query timeout in milliseconds.
-
#redis_url ⇒ Object
Redis URL for slow query storage.
-
#slow_query_threshold_ms ⇒ Object
Slow query threshold in milliseconds.
-
#stats_collection ⇒ Object
Whether to start the background stats collector on boot.
Instance Method Summary collapse
- #ai_enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sql_genius/configuration.rb', line 83 def initialize @featured_tables = [] @blocked_tables = [ "sessions", "ar_internal_metadata", "schema_migrations", ] @masked_column_patterns = ["password", "secret", "digest", "token"] @default_columns = {} @max_row_limit = 1000 @default_row_limit = 25 @query_timeout_ms = 30_000 @authenticate = ->(_controller) { true } @ai_client = nil @ai_endpoint = nil @ai_api_key = nil @ai_model = nil @ai_auth_style = :api_key @ai_system_context = nil @slow_query_threshold_ms = 250 @redis_url = nil @audit_logger = nil @base_controller = "ActionController::Base" @stats_collection = true @min_unused_index_scans = 0 end |
Instance Attribute Details
#ai_api_key ⇒ Object
Returns the value of attribute ai_api_key.
40 41 42 |
# File 'lib/sql_genius/configuration.rb', line 40 def ai_api_key @ai_api_key end |
#ai_auth_style ⇒ Object
AI auth style: :bearer (OpenAI, Ollama Cloud) or :api_key (Azure OpenAI). Defaults to :api_key for backwards compatibility.
48 49 50 |
# File 'lib/sql_genius/configuration.rb', line 48 def ai_auth_style @ai_auth_style end |
#ai_client ⇒ Object
AI configuration — set to nil to disable AI features entirely. Must respond to :call(messages:, response_format:, temperature:) and return a Hash with “choices” in OpenAI-compatible format, OR set ai_endpoint + ai_api_key for a direct OpenAI-compatible HTTP API.
38 39 40 |
# File 'lib/sql_genius/configuration.rb', line 38 def ai_client @ai_client end |
#ai_endpoint ⇒ Object
Returns the value of attribute ai_endpoint.
39 40 41 |
# File 'lib/sql_genius/configuration.rb', line 39 def ai_endpoint @ai_endpoint end |
#ai_model ⇒ Object
AI model name to pass in the request body (e.g. “gpt-4o”, “gpt-3.5-turbo”). Optional — if nil, the API default or deployment model is used.
44 45 46 |
# File 'lib/sql_genius/configuration.rb', line 44 def ai_model @ai_model end |
#ai_system_context ⇒ Object
Custom system prompt prepended to AI suggestions. Use this to describe your domain, table relationships, and naming conventions.
52 53 54 |
# File 'lib/sql_genius/configuration.rb', line 52 def ai_system_context @ai_system_context end |
#audit_logger ⇒ Object
Logger instance for audit logging. Defaults to a file logger. Set to nil to disable audit logging.
62 63 64 |
# File 'lib/sql_genius/configuration.rb', line 62 def audit_logger @audit_logger end |
#authenticate ⇒ Object
Proc that receives the controller instance and returns true if the user is authorized. Example:
config.authenticate = ->(controller) { controller.current_user&.admin? }
32 33 34 |
# File 'lib/sql_genius/configuration.rb', line 32 def authenticate @authenticate end |
#base_controller ⇒ Object
Base controller class for the engine to inherit from. Set to “ApplicationController” to get current_user and other app helpers. Defaults to “ActionController::Base”.
67 68 69 |
# File 'lib/sql_genius/configuration.rb', line 67 def base_controller @base_controller end |
#blocked_tables ⇒ Object
Tables that must never be queried (auth, sessions, internal Rails tables).
10 11 12 |
# File 'lib/sql_genius/configuration.rb', line 10 def blocked_tables @blocked_tables end |
#default_columns ⇒ Object
Default columns to check in the visual builder, keyed by table name. Example: { “users” => %w[id name email created_at] }
18 19 20 |
# File 'lib/sql_genius/configuration.rb', line 18 def default_columns @default_columns end |
#default_row_limit ⇒ Object
Default row limit when none is specified.
24 25 26 |
# File 'lib/sql_genius/configuration.rb', line 24 def default_row_limit @default_row_limit end |
#featured_tables ⇒ Object
Tables to feature in the visual builder dropdown (array of strings). When empty, all non-blocked tables are shown.
7 8 9 |
# File 'lib/sql_genius/configuration.rb', line 7 def featured_tables @featured_tables end |
#masked_column_patterns ⇒ Object
Column name patterns to mask with [REDACTED] in query results. Matched case-insensitively via String#include?.
14 15 16 |
# File 'lib/sql_genius/configuration.rb', line 14 def masked_column_patterns @masked_column_patterns end |
#max_row_limit ⇒ Object
Maximum rows a single query can return.
21 22 23 |
# File 'lib/sql_genius/configuration.rb', line 21 def max_row_limit @max_row_limit end |
#min_unused_index_scans ⇒ Object
Maximum scan count for an index to still be considered “unused” by the Unused Indexes dashboard. The default (0) means only indexes that have never been scanned since the stats source was last reset are flagged. Raise this to ignore indexes that are technically used but rarely enough to be worth dropping (e.g. min_unused_index_scans = 50 to require at least 50 scans before considering an index “useful”).
81 82 83 |
# File 'lib/sql_genius/configuration.rb', line 81 def min_unused_index_scans @min_unused_index_scans end |
#query_timeout_ms ⇒ Object
Query timeout in milliseconds.
27 28 29 |
# File 'lib/sql_genius/configuration.rb', line 27 def query_timeout_ms @query_timeout_ms end |
#redis_url ⇒ Object
Redis URL for slow query storage. Set to nil to disable slow query monitoring.
58 59 60 |
# File 'lib/sql_genius/configuration.rb', line 58 def redis_url @redis_url end |
#slow_query_threshold_ms ⇒ Object
Slow query threshold in milliseconds. Queries slower than this are logged.
55 56 57 |
# File 'lib/sql_genius/configuration.rb', line 55 def slow_query_threshold_ms @slow_query_threshold_ms end |
#stats_collection ⇒ Object
Whether to start the background stats collector on boot. When enabled, performance_schema is sampled periodically and stored in an in-memory ring buffer accessible via SqlGenius.stats_history. Defaults to true.
73 74 75 |
# File 'lib/sql_genius/configuration.rb', line 73 def stats_collection @stats_collection end |
Instance Method Details
#ai_enabled? ⇒ Boolean
110 111 112 |
# File 'lib/sql_genius/configuration.rb', line 110 def ai_enabled? !ai_client.nil? || (!ai_endpoint.nil? && !ai_endpoint.empty? && !ai_api_key.nil? && !ai_api_key.empty?) end |