Module: CodeToQuery

Defined in:
lib/code_to_query.rb,
lib/code_to_query/query.rb,
lib/code_to_query/errors.rb,
lib/code_to_query/runner.rb,
lib/code_to_query/planner.rb,
lib/code_to_query/railtie.rb,
lib/code_to_query/version.rb,
lib/code_to_query/compiler.rb,
lib/code_to_query/validator.rb,
lib/code_to_query/llm_client.rb,
lib/code_to_query/context/pack.rb,
lib/code_to_query/configuration.rb,
lib/code_to_query/providers/base.rb,
lib/code_to_query/context/builder.rb,
lib/code_to_query/providers/local.rb,
lib/code_to_query/providers/openai.rb,
lib/code_to_query/performance/cache.rb,
lib/code_to_query/guardrails/sql_linter.rb,
lib/code_to_query/performance/optimizer.rb,
lib/code_to_query/guardrails/explain_gate.rb,
lib/code_to_query/policies/pundit_adapter.rb

Defined Under Namespace

Modules: BackCompat, Context, Guardrails, Performance, Policies, Providers Classes: Compiler, Configuration, ConnectionError, Error, ExecutionError, LLMClient, NotRelationConvertibleError, Planner, Query, Railtie, Runner, Validator

Constant Summary collapse

VERSION =

Gem version

'0.1.0'

Class Method Summary collapse

Class Method Details

.ask(prompt:, schema: nil, allow_tables: nil, current_user: nil) ⇒ Object

Convert natural language to SQL query current_user is optional and only used if a policy_adapter requires it



80
81
82
83
84
85
86
87
88
89
# File 'lib/code_to_query.rb', line 80

def self.ask(prompt:, schema: nil, allow_tables: nil, current_user: nil)
  intent = Planner.new(config).plan(prompt: prompt, schema: schema, allow_tables: allow_tables)
  validated_intent = Validator.new.validate(intent, current_user: current_user, allow_tables: allow_tables).deep_stringify_keys
  compiled = Compiler.new(config).compile(validated_intent, current_user: current_user)

  Guardrails::SqlLinter.new(config, allow_tables: allow_tables).check!(compiled[:sql])

  Query.new(sql: compiled[:sql], params: compiled[:params], bind_spec: compiled[:bind_spec],
            intent: validated_intent, allow_tables: allow_tables, config: config)
end

.configObject

Access the current configuration



73
74
75
76
# File 'lib/code_to_query.rb', line 73

def self.config
  BackCompat.ensure_extended_config!(Configuration.instance)
  Configuration.instance
end

.configure {|Configuration.instance| ... } ⇒ Object

Configure the gem

Yields:



67
68
69
70
# File 'lib/code_to_query.rb', line 67

def self.configure
  BackCompat.ensure_extended_config!(Configuration.instance)
  yield(Configuration.instance)
end