sql writer
This commit is contained in:
45
pkg/writers/pgsql/templates/fragments.tmpl
Normal file
45
pkg/writers/pgsql/templates/fragments.tmpl
Normal file
@@ -0,0 +1,45 @@
|
||||
{{/* Reusable template fragments */}}
|
||||
|
||||
{{/* Column definition fragment */}}
|
||||
{{- define "column_definition" -}}
|
||||
{{.Name}} {{.Type}}
|
||||
{{- if .Default}} 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" -}}
|
||||
{{.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 -}}
|
||||
Reference in New Issue
Block a user