Execute custom SQL queries using the Akron CLI across SQLite, MySQL, PostgreSQL, and MongoDB.
The raw-sql
command allows you to execute custom SQL queries directly against your database. Perfect for data analysis, debugging, and one-off database operations.
akron raw-sql --db <database_url> --query <sql_query>
This command executes SQL directly against your database. Be extremely careful with UPDATE, DELETE, and DROP statements, especially on production databases.
Type: str (required)
Database connection URL to execute query against.
Type: str (required)
SQL query to execute. Use quotes for multi-word queries.
Type: str (optional)
Path to SQL file to execute (alternative to --query).
Type: str (optional)
Output format: "table", "json", or "csv". Default: "table"
Type: str (optional)
Save results to file instead of displaying in terminal.
Query Results: ============== +----+----------+-------------------+ | id | username | email | +----+----------+-------------------+ | 1 | admin | admin@example.com | | 2 | john_doe | john@example.com | | 3 | jane_s | jane@example.com | +----+----------+-------------------+ 3 rows returned in 0.002 seconds
Query Results: ============== +-------------+---------------+-----------+ | category | product_count | avg_price | +-------------+---------------+-----------+ | Electronics | 150 | 249.99 | | Clothing | 89 | 45.50 | | Books | 45 | 19.99 | +-------------+---------------+-----------+ 3 rows returned in 0.045 seconds
Query Results from user_stats.sql: =================================== +----------+------------+---------------------+ | username | post_count | last_post | +----------+------------+---------------------+ | alice | 25 | 2024-01-15 14:30:00 | | bob | 18 | 2024-01-14 09:15:00 | | charlie | 12 | 2024-01-13 16:45:00 | +----------+------------+---------------------+ 3 rows returned in 0.012 seconds
JSON Output: ============ [ { "_id": "507f1f77bcf86cd799439011", "username": "alice", "email": "alice@example.com" }, { "_id": "507f1f77bcf86cd799439012", "username": "bob", "email": "bob@example.com" } ] CSV saved to: sales_data.csv