sqlc_skill

This skill helps you generate type-safe Go code from SQL queries with sqlc across SQLite, PostgreSQL, and MySQL.
  • Go

241

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kalbasit/ncps --skill sqlc

  • SKILL.md1.8 KB

Overview

This skill documents how to work with sqlc in the NCPS repository to produce type-safe Go database code for SQLite, PostgreSQL, and MySQL. It describes where SQL sources live, where generated code is written, and the required workflow when queries change. The goal is reliable, consistent database query generation and safe integration with Go code.

How this skill works

sqlc reads SQL query files for each supported engine and generates Go types and query implementations into engine-specific output packages. After generation, a go generate step extracts a common Querier interface and shared domain models, then creates thin wrappers for each backend. The process enforces a single source of truth for queries while keeping application code engine-agnostic.

When to use it

  • After making any change to db/query.<engine>.sql files
  • When adding new query methods or altering result columns/types
  • When switching or supporting an additional database engine
  • Before committing changes that affect database behavior
  • When updating domain models that depend on query results

Best practices

  • Run sqlfluff lint and sqlfluff format on db/query.*.sql before generation
  • Always run sqlc generate after editing SQL files to keep generated code in sync
  • Run go generate ./pkg/database to regenerate the common Querier and models
  • Keep equivalent queries for all supported engines unless intentionally engine-specific
  • Never manually edit generated files like pkg/database/querier.go or models.go

Example use cases

  • Add a new SELECT query to db/query.postgres.sql and regenerate to expose a new typed method in postgresdb
  • Refactor a query that changes returned columns: update SQL, run sqlc generate, then go generate to update shared models
  • Introduce a MySQL-specific optimization: add query to db/query.mysql.sql and maintain consistent interfaces via generated wrappers
  • Audit SQL formatting and correctness by running sqlfluff then regenerate to ensure consistent codegen

FAQ

Always run sqlc generate to update generated Go files, then run go generate ./pkg/database to refresh shared Querier and wrappers.

Can I edit the generated querier or models by hand?

No. pkg/database/querier.go and pkg/database/models.go are autogenerated and will be overwritten; apply changes via SQL or generator templates.

How do I keep queries consistent across engines?

Maintain equivalent SQL files for each engine and include engine-specific deviations only when necessary; use linting to enforce style.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational