Examples
All 32 runnable examples demonstrating sqlite.zig features.
Getting Started
| # | Example | Description |
|---|---|---|
| 01 | Open & Exec | Open a database and execute raw SQL |
| 02 | Prepared Statement | Parameterized queries with prepared statements |
| 03 | Transactions | BEGIN, COMMIT, ROLLBACK with typed DSL |
DSL Basics
| # | Example | Description |
|---|---|---|
| 04 | DSL Query Builder | Type-safe comptime query builder basics |
| 09 | DSL CRUD | Full CRUD operations via typed DSL |
| 10 | DSL Advanced | Advanced DSL queries and predicates |
| 14 | Select Projections | SELECT field projections with selectFields() |
| 16 | Predicates & Pagination | WHERE predicates with LIMIT/OFFSET |
SQL Features
| # | Example | Description |
|---|---|---|
| 05 | Migrations | Schema migration patterns |
| 06 | Error Handling | Error handling and recovery |
| 11 | Keys & Joins | Primary keys, foreign keys, and JOIN queries |
| 12 | Complex Queries | DISTINCT joins and aggregate functions |
| 13 | Edge Cases | NULL handling, savepoints, and error cases |
Advanced
| # | Example | Description |
|---|---|---|
| 07 | Python Interop | Interop with Python sqlite3 module |
| 08 | Repair Legacy | Repair and legacy database handling |
| 15 | Raw & DSL Interop | Verify raw SQL and DSL produce identical results |
| 17 | Persistence | Data persistence across database close/reopen |
| 18 | Schema Lifecycle | CREATE, ALTER, DROP table lifecycle |
| 19 | Prepared Parameters | Typed parameter binding in prepared statements |
| 20 | Scalar Functions | ABS, LENGTH, UPPER, LOWER, SUBSTR functions |
| 21 | Indexed Queries | Index creation and optimized lookups |
| 22 | Views | CREATE VIEW with typed DSL reads |
| 23 | Triggers | BEFORE/AFTER INSERT triggers |
| 24 | CTEs | Common Table Expressions with typed reads |
| 25 | Subqueries | Subqueries in FROM and WHERE clauses |
| 26 | FK Actions | CASCADE DELETE and SET NULL actions |
| 27 | Composite Unique | Composite unique constraints |
| 28 | FK Update Actions | CASCADE UPDATE and SET DEFAULT actions |
| 29 | Multiple CTEs | Multiple CTEs with cross-CTE joins |
| 30 | Composite Constraints | Composite PRIMARY KEY and UNIQUE |
| 31 | Composite FKs | Composite foreign keys referencing multiple columns |
| 32 | Recursive CTEs | Recursive CTEs for hierarchical tree traversal |
Running Examples
bash
# Run a specific example
zig build run-01_open_and_exec
# Run all examples
zig build run-all-examples