Class: Tidewave::Tools::ExecuteSqlQuery
- Defined in:
- lib/tidewave/tools/execute_sql_query.rb
Constant Summary collapse
- RESULT_LIMIT =
50
Instance Method Summary collapse
Methods inherited from Base
file_system_tool, file_system_tool?
Instance Method Details
#call(query:, arguments: []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tidewave/tools/execute_sql_query.rb', line 27 def call(query:, arguments: []) # Get the ActiveRecord connection conn = ActiveRecord::Base.connection # Execute the query with prepared statement and arguments if arguments.any? result = conn.exec_query(query, "SQL", arguments) else result = conn.exec_query(query) end # Format the result { columns: result.columns, rows: result.rows.first(RESULT_LIMIT), row_count: result.rows.length, adapter: conn.adapter_name, database: Rails.configuration.database_configuration.dig(Rails.env, "database") } end |