Get the FREE Ultimate OpenClaw Setup Guide →

database

npx machina-cli add skill husniadil/ekstend/database --openclaw
Files (1)
SKILL.md
13.0 KB

Database CLI

Access and manage MySQL, PostgreSQL, SQLite databases, and Redis key-value stores using their respective command-line clients.

Critical Rules

NEVER do the following:

  • NEVER guess or assume table names - always list tables first with SHOW TABLES, \dt, or .tables
  • NEVER guess or assume column names - always describe the table first with DESCRIBE, \d, or PRAGMA table_info
  • NEVER run SELECT queries on an unfamiliar database without exploring the schema first
  • NEVER assume ORM naming conventions (e.g., Order vs orders, userId vs user_id) - verify with schema

ALWAYS follow the Query Workflow below when querying data the user asks for.

Database Type Detection

Determine the database type from context:

SignalDatabase Type
User says "MySQL", "mysql"MySQL
User says "PostgreSQL", "Postgres", "psql"PostgreSQL
User says "SQLite", "sqlite3"SQLite
File path ends in .db, .sqlite, .sqlite3SQLite
Connection string starts with mysql://MySQL
Connection string starts with postgresql://PostgreSQL
Connection string starts with postgres://PostgreSQL
Connection string starts with sqlite:///SQLite
Config has MYSQL_* variablesMySQL
Config has PG* or POSTGRES_* variablesPostgreSQL
Config has SQLITE_* or DATABASE_PATHSQLite
User says "Redis", "redis-cli"Redis
Connection string starts with redis://Redis
Connection string starts with rediss://Redis
Config has REDIS_* variablesRedis
Port 3306 mentionedMySQL
Port 5432 mentionedPostgreSQL
Port 6379 mentionedRedis

If database type cannot be determined, ask using AskUserQuestion:

Which database are you working with?
1. MySQL
2. PostgreSQL
3. SQLite
4. Redis

Prerequisites

Verify the appropriate CLI is installed:

DatabaseCommand
MySQLmysql --version
PostgreSQLpsql --version
SQLitesqlite3 --version
Redisredis-cli --version

If CLI is not installed, offer to help install it:

  1. Detect the OS using uname -s (Darwin=macOS, Linux=Linux)
  2. Ask the user using AskUserQuestion:
The [DATABASE] CLI is not installed. Would you like me to install it?

I detected you're on [OS]. I would run:
- [INSTALL_COMMAND]

1. Yes, install it for me
2. No, I'll install it myself

Installation commands by OS:

DatabasemacOS (Homebrew)Ubuntu/DebianArch Linux
MySQLbrew install mysql-clientsudo apt install mysql-clientsudo pacman -S mysql
PostgreSQLbrew install libpqsudo apt install postgresql-clientsudo pacman -S postgresql
SQLitebrew install sqlitesudo apt install sqlite3sudo pacman -S sqlite
Redisbrew install redissudo apt install redis-toolssudo pacman -S redis

For macOS with Homebrew, after installing mysql-client or libpq, the user may need to add to PATH:

  • MySQL: echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
  • PostgreSQL: echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc

Credential/Path Acquisition

CRITICAL: Never use environment variables from the shell without explicit user permission.

Ask the user using AskUserQuestion:

For MySQL/PostgreSQL:

How would you like to provide database credentials?
1. Enter credentials manually (host, user, password, database)
2. Read from a file (provide path to .env, docker-compose.yml, or config file)

For SQLite:

How would you like to provide the SQLite database path?
1. Enter the file path manually (e.g., ./data.db, /path/to/database.sqlite)
2. Read from a file (provide path to .env or config file)
3. Use in-memory database (:memory:)

For Redis:

How would you like to provide Redis connection details?
1. Enter connection details manually (host, port, password, database number)
2. Read from a file (provide path to .env, docker-compose.yml, or config file)

After reading any config file, confirm with user before connecting.

For detailed credential formats and CLI syntax, see the database-specific references:

Connection Test

Before any operation, test the connection using the appropriate command from the reference docs.

Query Workflow (For Unfamiliar Databases)

When user asks to query or check data, follow these steps in order:

Step 1: List Tables

First, discover what tables exist:

DatabaseCommand
MySQLSHOW TABLES
PostgreSQL\dt or \dt *.* (all schemas)
SQLite.tables or SELECT name FROM sqlite_master WHERE type='table'

Step 2: Identify Target Table

Match user's intent to actual table name:

  • User says "order" → look for orders, order, Order, tbl_orders, etc.
  • User says "user" → look for users, user, accounts, members, etc.
  • Do NOT assume - pick from the actual table list

Step 3: Describe Table Structure

Get actual column names before querying:

DatabaseCommand
MySQLDESCRIBE table_name
PostgreSQL\d table_name
SQLitePRAGMA table_info(table_name)

Step 4: Build and Execute Query

Now build the SELECT using actual column names from Step 3:

-- Use real columns, not guessed ones
SELECT actual_col1, actual_col2, actual_col3
FROM actual_table_name
ORDER BY created_at DESC
LIMIT 10;

Query Execution

Read Operations (SELECT)

Add LIMIT 100 to large result sets by default unless user specifies otherwise.

Write Operations (INSERT, UPDATE, DELETE)

ALWAYS require user confirmation before executing.

For UPDATE/DELETE, first show affected rows count, then ask: "This will affect X rows. Proceed? (yes/no)"

Redis Operations

Redis uses commands, not SQL queries. See references/redis.md for:

  • Key-value operations (GET, SET, DEL)
  • Data structure operations (lists, sets, hashes, sorted sets)
  • Key pattern exploration (SCAN, KEYS)
  • Official command reference: https://redis.io/docs/latest/commands/

Schema Exploration (SQL Databases)

Common operations (see reference docs for exact syntax):

OperationDescription
List databasesShow available databases
List tablesShow tables in database
Describe tableShow column structure
Show createShow CREATE statement
List indexesShow indexes on table

Safety Rules

Destructive Operations - REQUIRE CONFIRMATION

These operations MUST show a warning and require explicit user confirmation:

OperationRisk LevelAction Before Execute
DROP TABLE/DATABASECRITICALShow what will be dropped, require "yes"
TRUNCATE TABLECRITICALShow row count, require "yes"
DELETE without WHERECRITICALRefuse or require explicit confirmation
UPDATE without WHERECRITICALRefuse or require explicit confirmation
DELETE with WHEREHIGHShow affected count, require confirmation
UPDATE with WHEREHIGHShow affected count, require confirmation
ALTER TABLEMEDIUMDescribe changes, require confirmation
VACUUM (SQLite)LOWInform user (compacts database)

Redis Destructive Operations - REQUIRE CONFIRMATION

OperationRisk LevelAction Before Execute
FLUSHDBCRITICALShow database number, warn all keys deleted
FLUSHALLCRITICALWarn ALL databases cleared, require "yes"
DEL with patternCRITICALShow matching key count first, require "yes"
UNLINK with patternCRITICALShow matching key count first, require "yes"
KEYS * on productionHIGHWarn about blocking, suggest SCAN instead
CONFIG SETHIGHShow what will change, require confirmation
DEBUG *CRITICALRefuse unless explicit permission
SHUTDOWNCRITICALWarn server will stop, require explicit "yes"

Password/Credential Security

  • NEVER echo password to terminal output
  • NEVER include password in error messages shown to user
  • NEVER print or show the full command that contains passwords to the user
  • When executing commands, do NOT display the command itself - only show the query results
  • Do not log queries containing passwords

Production/System Database Warning

Show warning if:

  • Host/path contains: prod, production, live, master
  • Cloud database hostnames (RDS, Cloud SQL, Azure, Redis Cloud, ElastiCache)
  • System databases (browser DBs, /Library/, /var/lib/)

SQLite File Safety

  • Verify database path before operations
  • Warn if creating a new database file
  • Don't modify system SQLite databases without explicit permission (browser DBs, OS DBs)

Common SQL Operations

These work across MySQL, PostgreSQL, and SQLite (Redis uses commands, not SQL):

-- List all records (with limit)
SELECT * FROM table_name LIMIT 100;

-- Find by condition
SELECT * FROM table_name WHERE column = 'value' LIMIT 100;

-- Count records
SELECT COUNT(*) FROM table_name;

-- Recent records
SELECT * FROM table_name ORDER BY created_at DESC LIMIT 10;

-- Insert
INSERT INTO table_name (col1, col2) VALUES ('val1', 'val2');

-- Update (show count first, then confirm)
UPDATE table_name SET col1 = 'value' WHERE condition;

-- Delete (show count first, then confirm)
DELETE FROM table_name WHERE condition;

Database-Specific References

For detailed CLI commands, credential formats, and database-specific features:

Error Handling

Common errors across databases:

Error TypeLikely CauseSuggestion
Connection refusedService not runningCheck if database is running
Access deniedWrong credentialsVerify username/password
Database not foundWrong database nameList available databases
Table not foundWrong table nameList tables in database
Permission deniedInsufficient privilegesCheck user permissions
Syntax errorInvalid SQLCheck query syntax
NOAUTH (Redis)Redis requires passwordAdd -a PASSWORD flag
WRONGTYPE (Redis)Wrong Redis data typeCheck key type with TYPE command

See database-specific references for detailed error handling.

Source

git clone https://github.com/husniadil/ekstend/blob/main/plugins/database/skills/database/SKILL.mdView on GitHub

Overview

Database CLI lets you access and manage MySQL, PostgreSQL, SQLite databases, and Redis via their command-line tools. It enforces safe practices by mandating schema exploration before queries and never guessing table or column names. This approach helps prevent unintended data changes and speeds up accurate data retrieval.

How This Skill Works

First, it detects the database type from your context or connection details (MySQL, PostgreSQL, SQLite, or Redis). Before querying, it requires listing tables with SHOW TABLES, \\dt, or .tables and describing a target table with DESCRIBE, \\d, or PRAGMA table_info to learn the schema. It then follows the Query Workflow to run queries only after schema exploration.

When to Use It

  • You need to access data from an unfamiliar database (MySQL, PostgreSQL, SQLite, or Redis) and must explore the schema first.
  • You are about to run a SELECT/INSERT/UPDATE/DELETE and want to confirm table and column names before executing.
  • You manage multiple DB types via CLI and want a consistent, schema-first workflow.
  • You want to prevent accidental changes by listing tables and describing structures before querying.
  • You need guidance on installing the appropriate CLI if it’s missing or not detected.

Quick Start

  1. Step 1: Detect the database type from context and verify the appropriate CLI is installed.
  2. Step 2: List tables with SHOW TABLES, \\dt, or .tables for the detected DB.
  3. Step 3: Describe a target table (DESCRIBE, \\d, or PRAGMA table_info) and run a safe SELECT using verified column names.

Best Practices

  • Always start by listing tables with SHOW TABLES, \\dt, or .tables before any data access.
  • Describe the target table with DESCRIBE, \\d, or PRAGMA table_info before running queries.
  • Avoid assuming ORM names; verify with the actual schema and names.
  • Follow the Database Query Workflow and only run queries after schema exploration.
  • Verify permissions and have a safe rollback plan when performing data-changing operations.

Example Use Cases

  • MySQL: list tables, describe orders, then run SELECT order_id, total FROM orders WHERE status='open';
  • PostgreSQL: \\dt; \\d orders; then SELECT id, customer_id FROM public.orders WHERE status='open';
  • SQLite: .tables; PRAGMA table_info(orders); then SELECT * FROM orders WHERE created_at > date('now','-30 day');
  • Redis: connect with redis-cli, inspect keys for a known prefix, then GET/SCAN values after confirming data model.
  • Unfamiliar schema: always enumerate tables and describe their columns before choosing a query path.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers