The queries agent executes SQL queries across Hyperdrive-connected databases with built-in safety, performance, and transformation features.Key Features:
Support for named queries from catalog (coming soon)
output: rows: array # Query results (array of objects) count: integer # Number of rows returned metadata: columns: string[] # Column names executionTime: number # Execution time in milliseconds cached: boolean # Whether result was from cache database: string # Database binding used query: string # Executed query (if includeMetadata is true)
Use :paramName placeholders in your SQL and provide values as an object:
input: sql: "SELECT * FROM products WHERE category = :category AND price BETWEEN :minPrice AND :maxPrice" input: category: "electronics" minPrice: 100 maxPrice: 1000
SQL with named parameters:
SELECT * FROM ordersWHERE user_id = :userId AND status = :status AND created_at > :startDateORDER BY created_at DESCLIMIT :limit
Find users by email or ID with optional filtering:
SELECT id, email, name, status, created_at, last_loginFROM usersWHERE (email = :email OR :email IS NULL) AND (id = :userId OR :userId IS NULL) AND (status = :status OR :status IS NULL)ORDER BY created_at DESCLIMIT 100;
SELECT id, name, description, price, category, inventory_count, rating, review_count, image_urlFROM productsWHERE (name LIKE '%' || :searchTerm || '%' OR description LIKE '%' || :searchTerm || '%') AND (category = :category OR :category IS NULL) AND (price >= :minPrice OR :minPrice IS NULL) AND (price <= :maxPrice OR :maxPrice IS NULL) AND (inventory_count > 0 OR :inStock = FALSE)ORDER BY rating DESC, review_count DESCLIMIT :limitOFFSET :offset;
SELECT DATE(event_time) as date, event_type, COUNT(*) as event_count, COUNT(DISTINCT user_id) as unique_users, AVG(value) as avg_value, SUM(value) as total_valueFROM eventsWHERE event_time >= :startDate AND event_time <= :endDateGROUP BY DATE(event_time), event_typeORDER BY date DESC, event_count DESC;