{"modulePath":"github.com/vidyesh95/Go-Tutorial","version":"v0.0.0-20261123112932-610d9af314ca","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package main\n\nLesson 09: sqlc, compile-time checked SQL.\n\nsqlc flips the usual ORM idea: YOU write plain SQL in query.sql, and sqlc GENERATES the Go code (structs, params, methods) by reading your schema and queries.\n\n\tsqlc.yaml  +  ../sql/schema.sql  +  query.sql   -\u003e   `go tool sqlc generate`   -\u003e   db/*.go\n\nWhat you get:\n\n  - Compile-time safety: a wrong column or table name fails at GENERATE time, and a changed column type breaks the Go build instead of production.\n  - No hand-written Scan code, no reflection at runtime, and no performance cost over database/sql: the generated methods call database/sql directly.\n  - Query annotations choose the Go signature: :one -\u003e (T, error)   :many -\u003e (\\[]T, error)   :exec -\u003e error   :execrows -\u003e (int64, error)\n  - sqlc.narg('x') makes a parameter nullable so you can write optional filters.\n  - db.New(sqlDB) works with \\*sql.DB or \\*sql.Tx (anything implementing DBTX), and q.WithTx(tx) rebinds the same Queries to a transaction.\n\nWorkflow:\n\n 1. edit schema.sql (or migrations) and query.sql\n 2. run \\`make sqlc\\` (this repo pins sqlc as a Go tool: \\`go tool sqlc generate -f ...\\`)\n 3. COMMIT the generated db/ folder: builds should not need sqlc installed, and diffs show exactly how a query change altered the code.\n\nGotchas:\n\n  - Never edit generated files; change the SQL and regenerate.\n  - SQLite is loosely typed, so sqlc maps every INTEGER to int64 and nullable columns to sql.NullString / sql.NullInt64. PostgreSQL gives richer types (and pgx integration).\n  - Dynamic queries (optional filters, variable column lists) are sqlc's weak spot. The sqlc.narg pattern below covers filters; for truly dynamic SQL use a query builder.\n\nIn industry: sqlc is very popular for Go services that want raw-SQL control with type safety. Typical layout: one sqlc.yaml per service, queries grouped by table in several .sql files, generated package named \\`db\\` or \\`sqlcgen\\`, wrapped by a thin repository/store layer.\n\n","path":"github.com/vidyesh95/Go-Tutorial/03-sql-sqlite/09sqlc","name":"main","synopsis":"Lesson 09: sqlc, compile-time checked SQL.","isRedistributable":true}
