LinuxCommandLibrary

sqlx

Rust SQL toolkit with compile-time checks

TLDR

Create database

$ sqlx database create
copy
Run migrations
$ sqlx migrate run
copy
Create migration
$ sqlx migrate add [migration_name]
copy
Revert migration
$ sqlx migrate revert
copy
Prepare offline
$ sqlx prepare
copy
Check queries
$ sqlx prepare --check
copy

SYNOPSIS

sqlx command [options]

DESCRIPTION

sqlx is a command-line tool for the SQLx Rust SQL toolkit that provides database migration management and compile-time query verification. It supports PostgreSQL, MySQL, MariaDB, and SQLite.
The migration system creates versioned SQL scripts that track schema changes, with commands to create, run, and revert migrations. The prepare command caches query metadata to a JSON file, enabling compile-time type checking of SQL queries in Rust code without requiring a live database connection during builds.
A DATABASE_URL environment variable or .env file must specify the database connection string for all operations.

PARAMETERS

database

Database operations.
migrate
Migration commands.
prepare
Prepare for offline.
--database-url URL
Connection string.
add
Add migration.
run
Run migrations.

CONFIGURATION

DATABASE_URL

Environment variable specifying the database connection string (e.g., postgres://user:pass@host/db, sqlite:data.db).
.env
Project-level file where DATABASE_URL can be defined; automatically loaded by sqlx commands.

CAVEATS

Rust development tool. DATABASE_URL required. Compile-time checks.

HISTORY

sqlx is a Rust SQL toolkit providing compile-time checked queries and database migrations.

SEE ALSO

diesel(1), psql(1), sqlite3(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community