Class: OmniAI::Tools::Database::BaseTool

Inherits:
OmniAI::Tool
  • Object
show all
Defined in:
lib/omniai/tools/database/base_tool.rb

Overview

Examples:

tool = OmniAI::Tools::Database::SqliteTool.new
tool.execute(path: "./foo/bar")

Direct Known Subclasses

SqliteTool

Instance Method Summary collapse

Constructor Details

#initialize(logger: Logger.new(IO::NULL)) ⇒ BaseTool

Returns a new instance of BaseTool.

Parameters:

  • logger (IO) (defaults to: Logger.new(IO::NULL))

    An optional logger for debugging executed commands.



13
14
15
16
# File 'lib/omniai/tools/database/base_tool.rb', line 13

def initialize(logger: Logger.new(IO::NULL))
  super()
  @logger = logger
end

Instance Method Details

#execute(statements:) ⇒ Array<Hash>

Examples:

tool = OmniAI::Tools::Database::BaseTool.new
tool.execute(statements: ["SELECT * FROM people"])

Parameters:

  • statements (Array<String>)

Returns:

  • (Array<Hash>)


25
26
27
28
29
30
31
32
33
# File 'lib/omniai/tools/database/base_tool.rb', line 25

def execute(statements:)
  [].tap do |executions|
    statements.map do |statement|
      execution = perform(statement:)
      executions << execution
      break unless execution[:status].eql?(:ok)
    end
  end
end