Class: OmniAI::Tools::Database::SqliteTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/omniai/tools/database/sqlite_tool.rb

Overview

Examples:

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

Instance Method Summary collapse

Constructor Details

#initialize(db:, logger: Logger.new(IO::NULL)) ⇒ SqliteTool

Returns a new instance of SqliteTool.

Parameters:

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

    An optional logger for debugging executed commands.

  • db (SQLite3::Database)

    A sqlite database.



69
70
71
72
# File 'lib/omniai/tools/database/sqlite_tool.rb', line 69

def initialize(db:, logger: Logger.new(IO::NULL))
  super(logger:)
  @db = db
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>)


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/omniai/tools/database/sqlite_tool.rb', line 81

def execute(statements:)
  @logger.info("#{self.class.name}#{__method__} statements=#{statements.inspect}")

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