LinuxCommandLibrary

cradle-sql

Run SQL queries against Cradle databases

TLDR

Rebuild the database schema

$ cradle sql build
copy

Rebuild the database schema for a specific package
$ cradle sql build [package]
copy

Empty the entire database
$ cradle sql flush
copy

Empty the database tables for a specific package
$ cradle sql flush [package]
copy

Populate the tables for all packages
$ cradle sql populate
copy

Populate the tables for a specific package
$ cradle sql populate [package]
copy

SYNOPSIS

cradle-sql [options] [SQL query]

PARAMETERS

--help
    Displays help information about the command and available options.

--version
    Displays the version of the `cradle-sql` tool.

--host
    Specifies the hostname or IP address of the Cradle database server.

--port
    Specifies the port number on which the Cradle database server is listening. Default port may vary based on the version.

--database
    Specifies the name of the Cradle database to connect to.

--username
    Specifies the username for authenticating with the Cradle database.

--password
    Specifies the password for authenticating with the Cradle database. Use with caution: can expose the password in command history.

-f
    Executes SQL statements from a file.

-e
    Executes a single SQL statement provided directly on the command line.

DESCRIPTION

The `cradle-sql` command is a command-line interface (CLI) tool used for interacting with a Cradle database from the command line. Cradle databases are NoSQL databases primarily focusing on versioning of documents. `cradle-sql` allows users to execute SQL-like queries against the database, inspect data, and perform administrative tasks. It's designed to be a versatile tool for developers and administrators working with Cradle databases, enabling them to automate tasks, troubleshoot issues, and explore the data stored within the Cradle system.

This tool simplifies many operational and development tasks such as data validation, ad-hoc query execution, schema inspection (if applicable), and basic database administration. It can be used in scripts, allowing for automation of data extraction and manipulation in Cradle.

CAVEATS

  • Security: Avoid storing passwords directly in scripts or command-line arguments. Consider using environment variables or secure configuration files.
  • Error Handling: Implement proper error handling in scripts to gracefully manage connection issues or query failures.

EXAMPLES

  • Connect to a Cradle database:
    cradle-sql --host localhost --port 6000 --database mydatabase --username myuser --password mypassword
  • Execute a SQL query:
    cradle-sql --host localhost --database mydatabase "SELECT * FROM documents WHERE type = 'report'"
  • Execute SQL from a file:
    cradle-sql --host localhost --database mydatabase -f query.sql

OUTPUT FORMAT

The `cradle-sql` tool typically presents the output of SQL queries in a tabular format, similar to other database CLIs. The exact format can vary depending on the tool's configuration and the specific query being executed. Check the documentation.

HISTORY

The `cradle-sql` command was developed alongside the Cradle NoSQL database to provide a command-line interface for interacting with the database. Its purpose is to simplify database administration, data querying, and development tasks for users of the Cradle system. The command's feature set and functionality have likely evolved over time to align with the features and capabilities of the Cradle database itself.

SEE ALSO

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

Copied to clipboard