Class: Tidewave::Tools::ExecuteSqlQuery
- Inherits:
-
Tidewave::Tool
- Object
- Tidewave::Tool
- Tidewave::Tools::ExecuteSqlQuery
- Defined in:
- lib/tidewave/tools/execute_sql_query.rb
Constant Summary collapse
- DESCRIPTION =
<<~DESCRIPTION.freeze Executes the given SQL query against the database connection. Returns the result as a Ruby data structure. Note that the output is limited to 50 rows at a time. If you need to see more, perform additional calls using LIMIT and OFFSET in the query. If you know that only specific columns are relevant, only include those in the SELECT clause. You can use this tool to select user data, manipulate entries, and introspect the application data domain. Always ensure to use the correct SQL commands for the database you are using. For PostgreSQL, use $1, $2, etc. for parameter placeholders. For MySQL, use ? for parameter placeholders. DESCRIPTION
Instance Method Summary collapse
- #call(arguments_hash) ⇒ Object
- #definition ⇒ Object
-
#initialize(options = {}) ⇒ ExecuteSqlQuery
constructor
A new instance of ExecuteSqlQuery.
Methods inherited from Tidewave::Tool
descendants, inherited, #validate_and_call
Constructor Details
#initialize(options = {}) ⇒ ExecuteSqlQuery
Returns a new instance of ExecuteSqlQuery.
19 20 21 |
# File 'lib/tidewave/tools/execute_sql_query.rb', line 19 def initialize( = {}) @database_adapter = Tidewave::DatabaseAdapter.for([:orm_adapter]) if [:orm_adapter] end |
Instance Method Details
#call(arguments_hash) ⇒ Object
48 49 50 51 52 |
# File 'lib/tidewave/tools/execute_sql_query.rb', line 48 def call(arguments_hash) query = arguments_hash.fetch("query") arguments = arguments_hash.fetch("arguments", []) @database_adapter.execute_query(query, arguments) end |
#definition ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tidewave/tools/execute_sql_query.rb', line 23 def definition return nil unless @database_adapter { "name" => "execute_sql_query", "description" => DESCRIPTION, "inputSchema" => { "type" => "object", "properties" => { "query" => { "type" => "string", "minLength" => 1, "description" => "The SQL query to execute. For PostgreSQL, use $1, $2 placeholders. For MySQL, use ? placeholders." }, "arguments" => { "type" => "array", "items" => {}, "description" => "The arguments to pass to the query. The query must contain corresponding parameter placeholders." } }, "required" => [ "query" ] } } end |