0PricingLogin
Learn Rust Coding · Lesson

Connecting to a Database

sqlx pools.

What is sqlx?

sqlx is an async, pure-Rust SQL toolkit. It is not an ORM; you write real SQL but get compile-time checking and type-safe results.

  • Supports Postgres, MySQL, SQLite
  • Built on async runtimes like Tokio

Adding sqlx

Declare sqlx with the runtime and database features you need. This edits Cargo.toml and runs in your terminal.

[dependencies]
sqlx = { version = "0.7", features = ["runtime-tokio", "postgres"] }
tokio = { version = "1", features = ["full"] }

All lessons in this course

  1. Connecting to a Database
  2. Compile-Time Checked Queries
  3. CRUD Operations
  4. Migrations
← Back to Learn Rust Coding