Search⌘ K
AI Features

Relational Databases (SQL): MySql, Postgres, SQLite

Explore how to use the sqlx crate in Rust to connect with multiple SQL databases including MySQL, Postgres, and SQLite. Understand connecting, executing queries, binding Rust variables, and retrieving data with practical examples.

Sqlx: The SQL toolkit

Working with a specific database is all well and good, but what if we want to have the option of choosing which back-end database to use? That’s where we can use sqlx, a crate that helps us interface with many different SQLSQL DBMS.

At the moment, sqlx supports the following types of databases:

  • MySQL/MariaDB
  • Postgres
  • SQLite
  • MSSQL

The support must be stated as a feature when loading the crate in our Cargo.toml. The asyncasync backend must be stated as well, like so:

 sqlx = { version = "0.5.9", features = ["mysql", "runtime-tokio-native-tls"] }

First steps

...