LinuxCommandLibrary

cradle-sql

execute SQL queries through Cradle framework

TLDR

Execute a SQL query

$ cradle sql "[SELECT * FROM users]"
copy
Run queries from a SQL file
$ cradle sql --file [queries.sql]
copy
Execute on a specific database connection
$ cradle sql --connection [mysql] "[query]"
copy
Export table to SQL file
$ cradle sql --export [table_name] > [backup.sql]
copy
Import SQL file into database
$ cradle sql --import [backup.sql]
copy
Show all tables
$ cradle sql "SHOW TABLES"
copy

SYNOPSIS

cradle sql [options] [query]

DESCRIPTION

cradle sql provides direct SQL access to databases configured in the Cradle framework. It allows executing queries, importing/exporting data, and performing database operations without needing a separate client.
The command uses the framework's database configuration, supporting multiple connections defined in the application settings. Results can be output in various formats suitable for display or processing by other tools.
This tool is useful for debugging, data inspection, and quick database operations during development. It maintains consistent authentication and connection handling with the rest of the Cradle application.

PARAMETERS

QUERY

SQL query to execute. Wrap in quotes.
--file FILE
Execute SQL commands from a file.
--connection NAME
Use a specific database connection.
--export TABLE
Export table data as SQL statements.
--import FILE
Import SQL file into the database.
--database NAME
Override the default database.
--format FORMAT
Output format: table, json, csv.
--help
Display help information.

CAVEATS

Direct SQL access bypasses application-level validations. Destructive queries (DROP, DELETE, TRUNCATE) execute without confirmation unless the framework adds safeguards. Always backup data before running potentially destructive operations.

HISTORY

cradle sql was developed as part of the Cradle PHP framework's CLI tools to provide convenient database access. It follows the pattern of framework-integrated database commands found in other PHP frameworks like Laravel's Artisan.

SEE ALSO

cradle(1), mysql(1), psql(1), sqlite3(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community