Skip to content
Back to skills

Sqlx Knowledge Patch

ASecurity

SQLx

  • 25 stars
  • 0 votes
  • 0 copies
  • 10 views
  • Added May 27, 2026
developmentrustgosqlawsapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill sqlx-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sqlx Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sqlx Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-sqlx-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-sqlx-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sqlx-knowledge-patch
description: SQLx
version: "0.9.1"
license: MIT
metadata:
  author: Nevaberry
---


# SQLx Knowledge Patch

Load this skill when configuring SQLx, adapting query and type integrations,
working with database-specific behavior, or using migrations and CLI commands.
Use the topic references for the detailed conditions and examples.

| Reference | Topics |
| --- | --- |
| [Installation and Configuration](references/installation-and-configuration.md) | Toolchain, CLI installation, runtimes, TLS providers and roots, per-crate configuration, offline support, dotenv handling |
| [Queries, Macros, and Types](references/queries-macros-and-types.md) | SQL strings, arguments, `RawSql`, decoding, derives, PostgreSQL types, macro nullability and environment lookup |
| [Database-Specific Behavior](references/database-specific-behavior.md) | PostgreSQL connection options and locks, MySQL authentication and row counts, SQLite linking, features, ownership, and decoding |
| [Migrations and Observability](references/migrations-and-observability.md) | Migrator APIs, migration transactions, CLI targets, filename validation, transaction state |

## Breaking changes and compatibility

### Toolchain and installation

SQLx 0.9.0 supports Rust 1.94.0 for this release cycle. Install `sqlx-cli`
without `--locked` after the removal of its tracked lockfile.

```sh
cargo install sqlx-cli --version 0.9.0
```

### Runtime, TLS, and offline features

SQLx 0.9 removes combined runtime and TLS flags. Replace
`runtime-tokio-native-tls` with `runtime-tokio` and `tls-native-tls`.
Runtime choices also include `runtime-smol` and `runtime-async-global-executor`.

Offline support is an optional `offline` feature in 0.9 so builds can omit the
Serde dependency from this functionality. The query macros give an
environment-supplied `SQLX_OFFLINE_DIR` precedence.

### Runtime SQL and owned arguments

In 0.9, the `query*()` functions accept `impl SqlSafeStr`. Static SQL strings
still work directly. For dynamically assembled statements, wrap trusted SQL
with `AssertSqlSafe` and bind values separately.

```rust
let sql = String::from("SELECT name FROM users WHERE id = $1");
let query = sqlx::query::<sqlx::Postgres>(sqlx::AssertSqlSafe(sql)).bind(42_i64);
```

Remove the lifetime parameter from `Arguments`, `SqliteArguments`, and
`AnyArguments` in custom implementations and signatures for 0.9. Owned SQL
and owned arguments allow a function to return a `Query<'static, DB>`.

### `RawSql` and advisory lock signatures

In 0.9, `RawSql` methods take a `DB` type parameter, which the compiler can
usually infer from the executor. `fetch_optional()` returns
`sqlx::Result<Option<DB::Row>>`.

Remove the lifetime argument from explicit `PgAdvisoryLockGuard` types in
0.9. Advisory lock acquisition is now cancellation-safe.

### SQLite ownership and decoding

In 0.9, `SqliteValue` is `!Sync` and `SqliteValueRef` is `!Send`. Clone an
owned value or protect shared access with a `Mutex`; convert a value reference
to owned before sending it across threads.

Once a value has been decoded as a borrowed `&str` or `&[u8]`, decoding that
value as a different type returns an error.

In 0.8, SQLite integer decoding reports overflow instead of truncating values.
Query macros can also infer `i64` for columns previously inferred as `i32`.

### Type derives and row conversion

In 0.9.1, deriving `sqlx::Type` on an enum with `#[repr(C)]` is a compile-time
error. Use an explicit integer representation such as `#[repr(i32)]` for an
integer-backed mapping.

In 0.8, failed `#[sqlx(try_from = "T")]` conversions return
`Error::ColumnDecode`. A `#[sqlx(default)]` fallback therefore applies to a
missing column and leaves conversion errors visible.

### Query macro inference and environment lookup

In 0.9, PostgreSQL query macros use generic plans for nullability inference.
This can change which query fields are generated as `Option<T>`.

In 0.9, MySQL text with a nonbinary collation can now infer as `String` where
query macros previously inferred `Vec<u8>`. The MySQL-backed `Any` driver
also distinguishes text from blobs in `AnyTypeInfo`.

In 0.9.1, query macros look for `.env` only within the Cargo workspace.
Put the file inside the workspace or export values such as `DATABASE_URL`
in the build environment.

### Migration API and filename checks

In 0.9, `set_ignore_missing()` and `set_locking()` return `&mut Self`.
Custom migration drivers need to update their `Migrate` implementations
for the trait changes.

SQLx 0.9.1 rejects `.sql` files in the migration directory whose filenames
fail validation. Name migrations with a numeric version and a description,
such as `20261117000000_create_users.sql`, and move unrelated SQL files
out of the directory.

## Configuration and connection quick reference

### Per-crate configuration

In 0.9, enable `sqlx-toml` in the library to read per-crate configuration;
the CLI enables it by default. `sqlx::_config` documents custom database URL
environment variables, macro type overrides, migration table names and
schemas, characters to ignore when hashing migrations, and preferences such
as choosing `chrono` when `time` is also enabled.

### Rustls providers and certificate roots

In 0.8.2, `tls-rustls-ring` selects `ring` and `tls-rustls-aws-lc-rs`
selects `aws-lc-rs`. With 0.8.3, use `tls-rustls-ring-webpki` for `ring`
with WebPKI CA certificates, or `tls-rustls-ring-native-roots` for platform
CA certificates. `tls-rustls-aws-lc-rs-native-roots` uses platform CA
certificates with the Rustls AWS-LC provider.

### MySQL authentication and TLS names

For MySQL connections without TLS, enable `mysql-rsa` alongside `mysql`
when `caching_sha2_password` or `sha256_password` requires RSA password
encryption.

Use `MySqlConnectOptions::tls_sni_servername()` or the `tls-sni-servername`
URL parameter to supply a TLS SNI name separately from the connection host.

### PostgreSQL connection addresses and escaping

In 0.9.1, `hostaddr` (`PGHOSTADDR`) supplies the connection IP address and
bypasses DNS resolution. Set `host` (`PGHOST`) alongside it to supply the
server name for TLS SNI when applicable.

In 0.9, SQLx automatically escapes values passed to
`PgConnectOptions::options()`; pass values without pre-escaping them.
It also interprets backslash escapes in the password field of `.pgpass`.

### SQLite linking and optional APIs

In 0.8.3, `sqlite-unbundled` links a system SQLite library, which must be
installed or supplied at build time. SQLx recommends SQLite 3.20.0 or newer
to avoid link errors. In 0.8.4, enable `sqlite-preupdate-hook` for the
preupdate API; with `sqlite-unbundled`, use a library built with preupdate
support to avoid link errors.

In 0.9, enable `sqlite-deserialize` for `SqliteConnection::serialize()` and
`deserialize()`, or `sqlite-unlock-notify` for unlock notifications.
Enable `sqlite-load-extension` for `SqliteConnectOptions::extension()` or
`extension_with_entrypoint()`. Extension loading requires unsafe opt-in,
including extension paths and entry points for macros or CLI in `sqlx.toml`.

## Query and migration quick reference

### Smart pointers and nullable JSON

SQLx 0.9 adds `Type`, `Encode`, and `Decode` implementations for `Box`,
`Arc`, `Rc`, and `Cow`, including `Arc<str>`, `Arc<[u8]>`, and the corresponding
`Rc` types. Decoding a `Cow` now always produces `Cow::Owned`, with a lifetime
independent of the row.

Use `#[sqlx(json(nullable))]`, available in 0.8.5, to decode SQL `NULL` as
`None` and a non-NULL JSON document as the inner type of an `Option<T>` field.

### Explicit migrations and transaction control

SQLx 0.9 adds `Migrator::with_migrations()` for an explicit migration set.
Put `-- no-transaction` on the first line of a PostgreSQL migration in 0.8
or a SQLite migration in 0.9 to run it outside a transaction.

Since 0.7.2, use `--target-version` with `sqlx migrate run` or
`sqlx migrate revert` to select the target migration version.

```sh
sqlx migrate run --target-version 3
```

In 0.8.5, use `Connection::begin_with()` to start a transaction with a
database-specific command and `Connection::is_in_transaction()` to check
the connection's transaction state.

### CLI dotenv handling

SQLx CLI 0.8.5 restores `.env` handling, so CLI commands can load
`DATABASE_URL` from a local `.env` file again. Starting with 0.8.5,
`--no-dotenv` is accepted in subcommand arguments, for example
`sqlx migrate run --no-dotenv`.

Files in this skill

  • SKILL.md9.4 KB
  • references/configuration.md1.3 KB
  • references/postgres-and-mysql.md1.2 KB
  • references/sqlite.md1.6 KB
  • references/transactions.md1.4 KB
  • references/type-system.md2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.