- bun: scanonly+generated for GENERATED columns; scanonly+identity for ALWAYS identity (PK gets identity only) - gorm: <-:false+generated / identity, same primary key rule - dbml: write GENERATED/IDENTITY column notes and read them back into the model - pgsql: emit generation/identity clauses in migration create-table and add-column, no DEFAULT - readmes updated
47 lines
1.2 KiB
Cheetah
47 lines
1.2 KiB
Cheetah
{{/* Reusable template fragments */}}
|
|
|
|
{{/* Column definition fragment */}}
|
|
{{- define "column_definition" -}}
|
|
{{.Name}} {{.Type}}
|
|
{{- if .Generated}} GENERATED ALWAYS AS ({{.Generated}}) STORED{{end}}
|
|
{{- if .Identity}} GENERATED {{.Identity}} AS IDENTITY{{end}}
|
|
{{- if and .Default (not .Generated) (not .Identity)}} DEFAULT {{.Default}}{{end}}
|
|
{{- if .NotNull}} NOT NULL{{end}}
|
|
{{- end -}}
|
|
|
|
{{/* Comma-separated column list */}}
|
|
{{- define "column_list" -}}
|
|
{{- range $i, $col := . -}}
|
|
{{- if $i}}, {{end}}{{$col}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Qualified table name */}}
|
|
{{- define "qualified_table" -}}
|
|
{{qual_table_raw .SchemaName .TableName}}
|
|
{{- end -}}
|
|
|
|
{{/* Index method clause */}}
|
|
{{- define "index_method" -}}
|
|
{{- if .IndexType}}USING {{.IndexType}}{{end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Uniqueness keyword */}}
|
|
{{- define "unique_keyword" -}}
|
|
{{- if .Unique}}UNIQUE {{end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Referential action clauses */}}
|
|
{{- define "referential_actions" -}}
|
|
{{- if .OnDelete}}
|
|
ON DELETE {{.OnDelete}}
|
|
{{- end}}
|
|
{{- if .OnUpdate}}
|
|
ON UPDATE {{.OnUpdate}}
|
|
{{- end}}
|
|
{{- end -}}
|
|
|
|
{{/* Comment statement */}}
|
|
{{- define "comment_on" -}}
|
|
COMMENT ON {{.ObjectType}} {{.ObjectName}} IS {{quote .Comment}};
|
|
{{- end -}} |