Source Repository: launchbadge/sqlx
This tutorial series explores SQLx, Rust's async SQL toolkit that provides compile-time checked queries without the complexity of an ORM. These tutorials are based on real examples from the SQLx repository and demonstrate practical patterns for building database-driven applications.
SQLx is a Rust library that lets you write SQL as SQL while providing compile-time verification of your queries. It supports PostgreSQL, MySQL, and SQLite, offering the performance of raw SQL with the safety guarantees of Rust's type system.
- MySQL Todo App - Building a CLI todo application with MySQL, covering basic CRUD operations and migrations
- PostgreSQL Todo App - Same todo app using PostgreSQL, exploring database-specific features
- SQLite Todo App - Lightweight SQLite implementation for embedded and local applications
- JSON Operations - Working with JSON data types and queries in PostgreSQL
- Listen/Notify - Real-time notifications using PostgreSQL's LISTEN/NOTIFY system
- Transaction Management - Advanced transaction handling and isolation levels
- Query Files - Organizing complex queries in separate SQL files
- Axum Social API - Building a RESTful social media API with Axum and PostgreSQL
- Multi-Database Architecture - Designing applications that work across multiple database backends
- SQLite Extensions - Leveraging SQLite's powerful extension ecosystem
By completing these tutorials, you'll understand:
- Compile-time Query Verification: How SQLx checks your SQL at compile time
- Database Migrations: Managing schema changes across environments
- Async Database Operations: Efficient async/await patterns with databases
- Type Safety: Mapping SQL types to Rust types safely
- Connection Management: Pooling and connection lifecycle management
- Error Handling: Robust error handling patterns for database operations
- Testing Strategies: Testing database code effectively
- Basic Rust knowledge (ownership, async/await, error handling)
- Basic SQL understanding
- Familiarity with at least one database system (MySQL, PostgreSQL, or SQLite)
Each tutorial is self-contained and includes:
- Problem context and motivation
- Step-by-step code walkthrough
- Key insights and best practices
- Links to the original source code
Start with the MySQL Todo App for a gentle introduction to SQLx fundamentals, then explore the advanced topics based on your specific needs.