← 返回命令列表

Linux command

sqlx 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Create database

sqlx database create

Run migrations

sqlx migrate run

Create migration

sqlx migrate add [migration_name]

Revert migration

sqlx migrate revert

Prepare offline

sqlx prepare

Check queries

sqlx prepare --check

说明

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.

参数

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

FAQ

What is the sqlx command used for?

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.

How do I run a basic sqlx example?

Run `sqlx database create` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does database do in sqlx?

Database operations.