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