Skip to content

Add custom types section with sql.Scanner/driver.Valuer#8

Open
coolai86 wants to merge 3 commits into
therootcompany:mainfrom
coolai86:feature/custom-types-scanner-valuer
Open

Add custom types section with sql.Scanner/driver.Valuer#8
coolai86 wants to merge 3 commits into
therootcompany:mainfrom
coolai86:feature/custom-types-scanner-valuer

Conversation

@coolai86

@coolai86 coolai86 commented Apr 5, 2026

Copy link
Copy Markdown

This PR adds guidance for using custom types with sqlc type overrides.

Changes

  • Add / pattern documentation
  • Add JSONB override configuration example
  • Add nullable types guidance for Go 1.22+ () and legacy types
  • Update PostgreSQL type mappings table to reference custom types

Why This Matters

sqlc type overrides work with any Go type implementing and . This is essential for:

  • JSONB columns: Automatic JSON marshaling to Go structs (no manual )
  • Domain-specific types: Currency, dates with timezones, etc.
  • Custom nullable types: Go 1.22+ for types without legacy equivalents

Example Impact

Before:

type Tenant struct { PaymentConfig []byte }
var cfg PaymentConfig
json.Unmarshal(tenant.PaymentConfig, &cfg) // manual work

After:

type Tenant struct { PaymentConfig *types.JSONB }
var cfg PaymentConfig
tenant.PaymentConfig.Get(&cfg) // one-liner

This pattern was used successfully in the authd project for payment config, OAuth claim mappings, and session data.

root added 3 commits April 5, 2026 00:07
Single-binary Go web application patterns:
- Project structure (cmd/, internal/, web/dist/)
- Single embed file pattern
- SPA routing with fallback handler
- Development mode patterns
- Anti-patterns to avoid

Framework-agnostic: no vite/esbuild references.
- Document sql.Scanner/driver.Valuer pattern for custom types
- Add JSONB override configuration example
- Add nullable types guidance (sql.Null[T] and legacy types)
- Update PostgreSQL type mappings table to reference custom types

This helps projects use sqlc effectively for JSONB columns,
domain-specific types, and custom nullable types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant