Skip to content

Examples

All 32 runnable examples demonstrating sqlite.zig features.

Getting Started

#ExampleDescription
01Open & ExecOpen a database and execute raw SQL
02Prepared StatementParameterized queries with prepared statements
03TransactionsBEGIN, COMMIT, ROLLBACK with typed DSL

DSL Basics

#ExampleDescription
04DSL Query BuilderType-safe comptime query builder basics
09DSL CRUDFull CRUD operations via typed DSL
10DSL AdvancedAdvanced DSL queries and predicates
14Select ProjectionsSELECT field projections with selectFields()
16Predicates & PaginationWHERE predicates with LIMIT/OFFSET

SQL Features

#ExampleDescription
05MigrationsSchema migration patterns
06Error HandlingError handling and recovery
11Keys & JoinsPrimary keys, foreign keys, and JOIN queries
12Complex QueriesDISTINCT joins and aggregate functions
13Edge CasesNULL handling, savepoints, and error cases

Advanced

#ExampleDescription
07Python InteropInterop with Python sqlite3 module
08Repair LegacyRepair and legacy database handling
15Raw & DSL InteropVerify raw SQL and DSL produce identical results
17PersistenceData persistence across database close/reopen
18Schema LifecycleCREATE, ALTER, DROP table lifecycle
19Prepared ParametersTyped parameter binding in prepared statements
20Scalar FunctionsABS, LENGTH, UPPER, LOWER, SUBSTR functions
21Indexed QueriesIndex creation and optimized lookups
22ViewsCREATE VIEW with typed DSL reads
23TriggersBEFORE/AFTER INSERT triggers
24CTEsCommon Table Expressions with typed reads
25SubqueriesSubqueries in FROM and WHERE clauses
26FK ActionsCASCADE DELETE and SET NULL actions
27Composite UniqueComposite unique constraints
28FK Update ActionsCASCADE UPDATE and SET DEFAULT actions
29Multiple CTEsMultiple CTEs with cross-CTE joins
30Composite ConstraintsComposite PRIMARY KEY and UNIQUE
31Composite FKsComposite foreign keys referencing multiple columns
32Recursive CTEsRecursive 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

Released under the MIT License.