sqlc generates type-safe database access code from annotated SQL queries and schema files. By reading CREATE TABLE statements and query annotations, sqlc produces functions with compile-time verified parameter and return types, eliminating runtime type assertion errors.
0 / 5 completed
1 / 5
What does sqlc generate from annotated SQL queries?
sqlc reads SQL query files annotated with -- name: QueryName :one/:many/:exec and generates type-safe functions in Go, Kotlin, or Python. Each query gets a corresponding function with strongly typed parameters and return types derived from the database schema.
2 / 5
A developer annotates a SQL query with -- name: GetUser :one. What does the :one annotation tell sqlc?
The :one annotation tells sqlc the query returns a single row. The generated function returns (Row, error). If no row is found, it returns sql.ErrNoRows. Use :many for multiple rows and :exec for queries with no result set.
3 / 5
Which file must sqlc read to understand the database schema and generate correct types?
sqlc reads SQL schema files containing CREATE TABLE statements to understand column types and constraints. You point sqlc at your migration files or a schema dump via the schema field in sqlc.yaml. No live database connection is needed at generation time.
4 / 5
A developer wants sqlc to use pgx/v5 instead of database/sql as the database driver. Where is this configured?
The sqlc.yaml configuration file controls all generation options. Setting sql_package: pgx/v5 under the gen.go section makes sqlc generate code using pgx types like pgx.Rows and pgtype instead of standard database/sql types.
5 / 5
What problem does sqlc solve compared to writing raw SQL with database/sql?
With database/sql, SQL results are scanned into interface{} values at runtime, making type mismatches only visible at runtime. sqlc generates compile-time type-safe code where parameter types and result struct fields are verified against the schema, catching errors before deployment.