Class: Boxcars::SQLBase Abstract

Inherits:
EngineBoxcar show all
Defined in:
lib/boxcars/boxcar/sql_base.rb

Overview

This class is abstract.

A Boxcar that interprets a prompt and executes SQL code to get answers Use one of the subclasses for ActiveRecord or Sequel

Direct Known Subclasses

SQLActiveRecord, SQLSequel

Constant Summary collapse

SQLDESC =

the description of this engine boxcar

"useful for when you need to query a database for %<name>s."
LOCKED_OUT_TABLES =
%w[schema_migrations ar_internal_metadata].freeze

Instance Attribute Summary collapse

Attributes inherited from EngineBoxcar

#engine, #prompt, #stop, #top_k

Attributes inherited from Boxcar

#description, #name, #parameters, #return_direct

Instance Method Summary collapse

Methods inherited from EngineBoxcar

#apply, #call, #check_output_keys, #extract_code, #generate, #input_key, #input_keys, #output_key, #output_keys, #predict, #prediction_input, #prediction_variables

Methods inherited from Boxcar

#apply, assi, #call, #conduct, hist, #input_keys, #load, #output_keys, #run, #save, syst, user, #validate_inputs, #validate_outputs

Constructor Details

#initialize(connection: nil, tables: nil, except_tables: nil, **kwargs) ⇒ SQLBase

Returns a new instance of SQLBase.

Parameters:

  • connection (ActiveRecord::Connection) (defaults to: nil)

    or [Sequel Object] The SQL connection to use for this boxcar.

  • tables (Array<String>) (defaults to: nil)

    The tables to use for this boxcar. Will use all if nil.

  • except_tables (Array<String>) (defaults to: nil)

    The tables to exclude from this boxcar. Will exclude none if nil.

  • kwargs (Hash)

    Any other keyword arguments to pass to the parent class. This can include :name, :description, :prompt, :top_k, :stop, and :engine



19
20
21
22
23
24
25
26
27
28
# File 'lib/boxcars/boxcar/sql_base.rb', line 19

def initialize(connection: nil, tables: nil, except_tables: nil, **kwargs)
  @connection = connection
  check_tables(tables, except_tables)
  kwargs[:name] ||= "Database"
  kwargs[:description] ||= format(SQLDESC, name: name)
  kwargs[:prompt] ||= my_prompt
  kwargs[:stop] ||= ["SQLResult:"]

  super(**kwargs)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



12
13
14
# File 'lib/boxcars/boxcar/sql_base.rb', line 12

def connection
  @connection
end

#the_tablesObject

Returns the value of attribute the_tables.



12
13
14
# File 'lib/boxcars/boxcar/sql_base.rb', line 12

def the_tables
  @the_tables
end

Instance Method Details

#prediction_additional(_inputs) ⇒ Object

Returns Hash The additional variables for this boxcar.

Returns:

  • Hash The additional variables for this boxcar.



31
32
33
# File 'lib/boxcars/boxcar/sql_base.rb', line 31

def prediction_additional(_inputs)
  { schema: schema, dialect: dialect }.merge super
end