sqlboiler/templates/19_auto_timestamps.tpl

83 lines
2.2 KiB
Smarty
Raw Normal View History

{{- define "timestamp_insert_helper" -}}
2016-08-29 14:38:19 +02:00
{{- if not .NoAutoTimestamps -}}
{{- $colNames := .Table.Columns | columnNames -}}
{{if containsAny $colNames "created_at" "updated_at"}}
2016-09-01 03:24:39 +02:00
currTime := time.Now().In(boil.GetLocation())
{{range $ind, $col := .Table.Columns}}
{{- if eq $col.Name "created_at" -}}
{{- if $col.Nullable}}
if o.CreatedAt.Time.IsZero() {
o.CreatedAt.Time = currTime
o.CreatedAt.Valid = true
}
{{- else}}
if o.CreatedAt.IsZero() {
o.CreatedAt = currTime
}
{{- end -}}
{{- end -}}
{{- if eq $col.Name "updated_at" -}}
{{- if $col.Nullable}}
if o.UpdatedAt.Time.IsZero() {
o.UpdatedAt.Time = currTime
o.UpdatedAt.Valid = true
}
{{- else}}
if o.UpdatedAt.IsZero() {
o.UpdatedAt = currTime
}
{{- end -}}
{{- end -}}
{{end}}
{{end}}
{{- end}}
{{- end -}}
{{- define "timestamp_update_helper" -}}
2016-08-29 14:38:19 +02:00
{{- if not .NoAutoTimestamps -}}
{{- $colNames := .Table.Columns | columnNames -}}
{{if containsAny $colNames "updated_at"}}
2016-09-01 03:24:39 +02:00
currTime := time.Now().In(boil.GetLocation())
{{range $ind, $col := .Table.Columns}}
{{- if eq $col.Name "updated_at" -}}
{{- if $col.Nullable}}
o.UpdatedAt.Time = currTime
o.UpdatedAt.Valid = true
{{- else}}
o.UpdatedAt = currTime
{{- end -}}
{{- end -}}
{{end}}
{{end}}
{{- end}}
{{end -}}
{{- define "timestamp_upsert_helper" -}}
{{- if not .NoAutoTimestamps -}}
{{- $colNames := .Table.Columns | columnNames -}}
{{if containsAny $colNames "created_at" "updated_at"}}
2016-09-01 03:24:39 +02:00
currTime := time.Now().In(boil.GetLocation())
{{range $ind, $col := .Table.Columns}}
{{- if eq $col.Name "created_at" -}}
{{- if $col.Nullable}}
if o.CreatedAt.Time.IsZero() {
o.CreatedAt.Time = currTime
o.CreatedAt.Valid = true
}
{{- else}}
if o.CreatedAt.IsZero() {
o.CreatedAt = currTime
}
{{- end -}}
{{- end -}}
{{- if eq $col.Name "updated_at" -}}
{{- if $col.Nullable}}
o.UpdatedAt.Time = currTime
o.UpdatedAt.Valid = true
{{- else}}
o.UpdatedAt = currTime
{{- end -}}
{{- end -}}
{{end}}
{{end}}
{{- end}}
{{end -}}