The CSQLY Command Line Interface (CLI) allows you to execute YAML queries directly from the command line without writing any code.
Install the CLI tool globally using the .NET CLI:
dotnet tool install --global CSQLY.CLIThe basic syntax for using the CLI:
csqly --file <path-to-yaml-file> --connection <connection-string> --type <database-type>Abbreviated options are also available:
csqly -f <path-to-yaml-file> -c <connection-string> -t <database-type>| Option | Abbreviation | Description |
|---|---|---|
--file |
-f |
Path to the YAML query file |
--connection |
-c |
Database connection string |
--type |
-t |
Database type (sqlite, mysql, postgres, sqlserver, oracle) |
--help |
-h |
Show help information |
--version |
-v |
Show version information |
csqly -f query.yaml -c "Data Source=mydb.sqlite" -t sqlitecsqly -f query.yaml -c "Server=localhost;Database=mydb;User ID=user;Password=password;" -t mysqlcsqly -f query.yaml -c "Host=localhost;Database=mydb;Username=user;Password=password;" -t postgrescsqly -f query.yaml -c "Server=localhost;Database=mydb;User ID=user;Password=password;" -t sqlservercsqly -f query.yaml -c "Data Source=MyOracleDB;User Id=user;Password=password;" -t oracleHere's a simple example of a YAML query file:
# query.yaml
select:
columns:
- id
- name
- email
from: users
where:
active: true
limit: 10By default, query results are displayed in a tabular format. Support for JSON, CSV, and other formats is planned for future releases.
You can use environment variables for sensitive information like connection strings:
# Set environment variable
export DB_CONNECTION="Server=localhost;Database=mydb;User ID=user;Password=password;"
# Use it in the command
csqly -f query.yaml -c "$DB_CONNECTION" -t mysqlcsqly -f query.yaml -c "Data Source=mydb.sqlite" -t sqlite | grep "specific-data"#!/bin/bash
# Script to run daily reports
REPORT_DATE=$(date +%Y-%m-%d)
echo "Running report for $REPORT_DATE"
csqly -f daily_report.yaml -c "$DB_CONNECTION" -t postgres-
Connection string format is incorrect:
- Make sure the connection string follows the correct format for your database type
-
YAML syntax errors:
- Validate your YAML structure using a YAML validator
- Check for proper indentation and spacing
-
Database permissions:
- Ensure the user specified in the connection string has sufficient permissions
-
Command not found error:
- Ensure the .NET CLI tools path is added to your system PATH
- Try reinstalling the tool with
dotnet tool update --global CSQLY.CLI