Class: SqlGenius::Core::Ai::SchemaReview

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_genius/core/ai/schema_review.rb

Overview

Reviews a schema for anti-patterns. Takes a specific table name (or nil to review the top 20 queryable tables).

Instance Method Summary collapse

Constructor Details

#initialize(client, config, connection) ⇒ SchemaReview

Returns a new instance of SchemaReview.



9
10
11
12
13
# File 'lib/sql_genius/core/ai/schema_review.rb', line 9

def initialize(client, config, connection)
  @client = client
  @config = config
  @connection = connection
end

Instance Method Details

#call(table) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/sql_genius/core/ai/schema_review.rb', line 15

def call(table)
  tables_to_review = table.nil? || table.to_s.empty? ? @connection.tables.first(20) : [table]
  schema_desc = SchemaContextBuilder.new(@connection).call(tables_to_review, detail: :basic)

  messages = [
    { role: "system", content: system_prompt },
    { role: "user",   content: schema_desc },
  ]
  @client.chat(messages: messages)
end