sqlc Models
go
Generate Go structs matching sqlc naming conventions with sql.Null types
Example Output
Generated from the pet-store sample schema:
go
// Generated by @sqldoc/templates/sqlc -- DO NOT EDIT
package models
import (
"database/sql"
"encoding/json"
"time"
)
type Adoption struct {
Id int32
PetId int32
OwnerId int32
AdoptedAt time.Time
AdoptionFee string
}
type AdoptionsAuditLog struct {
Id int64
TableName string
Operation string
OldData *json.RawMessage
NewData *json.RawMessage
ChangedAt time.Time
}
type Category struct {
Id int32
Name string
Description sql.NullString
}
type LegacyInventory struct {
Id int32
ItemName sql.NullString
OldSku sql.NullString
Quantity sql.NullInt32
}
type Location struct {
Id int32
Name string
Address string
City string
Zip sql.NullString
}
type MedicalRecord struct {
Id int32
PetId int32
VisitDate time.Time
Diagnosis string
Treatment sql.NullString
VetName sql.NullString
}
type Owner struct {
Id int32
Name string
Email string
Phone sql.NullString
CreatedAt sql.NullTime
}
type Pet struct {
Id int32
CategoryId sql.NullInt32
Name string
Sku string
Price string
InternalNotes sql.NullString
Status string
CreatedAt sql.NullTime
}
type Review struct {
Id int32
PetId int32
OwnerId int32
Rating int32
Body sql.NullString
LocationId sql.NullInt32
CreatedAt sql.NullTime
}
type StaffAuditLog struct {
Id int64
TableName string
Operation string
OldData *json.RawMessage
NewData *json.RawMessage
ChangedAt time.Time
}Usage
Add to your sqldoc.config.ts:
typescript
export default {
dialect: 'postgres',
schema: ['./schema.sql'],
codegen: [
{
template: 'sqlc',
output: './generated/models.go',
},
],
}Then run:
bash
sqldoc codegen