github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/templates/main/21_auto_timestamps.go.tpl (about) 1 {{- define "timestamp_insert_helper" -}} 2 {{- if not .NoAutoTimestamps -}} 3 {{- $alias := .Aliases.Table .Table.Name -}} 4 {{- $colNames := .Table.Columns | columnNames -}} 5 {{if containsAny $colNames (or $.AutoColumns.Created "created_at") (or $.AutoColumns.Updated "updated_at")}} 6 {{if not .NoContext -}} 7 if !boil.TimestampsAreSkipped(ctx) { 8 {{end -}} 9 currTime := time.Now().In(boil.GetLocation()) 10 {{range $ind, $col := .Table.Columns}} 11 {{- $colAlias := $alias.Column $col.Name -}} 12 {{- if eq $col.Name (or $.AutoColumns.Created "created_at") -}} 13 {{- if eq $col.Type "time.Time" }} 14 if o.{{$colAlias}}.IsZero() { 15 o.{{$colAlias}} = currTime 16 } 17 {{- else}} 18 if queries.MustTime(o.{{$colAlias}}).IsZero() { 19 queries.SetScanner(&o.{{$colAlias}}, currTime) 20 } 21 {{- end -}} 22 {{- end -}} 23 {{- if eq $col.Name (or $.AutoColumns.Updated "updated_at") -}} 24 {{- if eq $col.Type "time.Time"}} 25 if o.{{$colAlias}}.IsZero() { 26 o.{{$colAlias}} = currTime 27 } 28 {{- else}} 29 if queries.MustTime(o.{{$colAlias}}).IsZero() { 30 queries.SetScanner(&o.{{$colAlias}}, currTime) 31 } 32 {{- end -}} 33 {{- end -}} 34 {{end}} 35 {{if not .NoContext -}} 36 } 37 {{end -}} 38 {{end}} 39 {{- end}} 40 {{- end -}} 41 {{- define "timestamp_update_helper" -}} 42 {{- if not .NoAutoTimestamps -}} 43 {{- $alias := .Aliases.Table .Table.Name -}} 44 {{- $colNames := .Table.Columns | columnNames -}} 45 {{if containsAny $colNames (or $.AutoColumns.Updated "updated_at")}} 46 {{if not .NoContext -}} 47 if !boil.TimestampsAreSkipped(ctx) { 48 {{end -}} 49 currTime := time.Now().In(boil.GetLocation()) 50 {{range $ind, $col := .Table.Columns}} 51 {{- $colAlias := $alias.Column $col.Name -}} 52 {{- if eq $col.Name (or $.AutoColumns.Updated "updated_at") -}} 53 {{- if eq $col.Type "time.Time"}} 54 o.{{$colAlias}} = currTime 55 {{- else}} 56 queries.SetScanner(&o.{{$colAlias}}, currTime) 57 {{- end -}} 58 {{- end -}} 59 {{end}} 60 {{if not .NoContext -}} 61 } 62 {{end -}} 63 {{end}} 64 {{- end}} 65 {{end -}} 66 {{- define "timestamp_upsert_helper" -}} 67 {{- if not .NoAutoTimestamps -}} 68 {{- $alias := .Aliases.Table .Table.Name -}} 69 {{- $colNames := .Table.Columns | columnNames -}} 70 {{if containsAny $colNames (or $.AutoColumns.Created "created_at") (or $.AutoColumns.Updated "updated_at")}} 71 {{if not .NoContext -}} 72 if !boil.TimestampsAreSkipped(ctx) { 73 {{end -}} 74 currTime := time.Now().In(boil.GetLocation()) 75 {{range $ind, $col := .Table.Columns}} 76 {{- $colAlias := $alias.Column $col.Name -}} 77 {{- if eq $col.Name (or $.AutoColumns.Created "created_at") -}} 78 {{- if eq $col.Type "time.Time"}} 79 if o.{{$colAlias}}.IsZero() { 80 o.{{$colAlias}} = currTime 81 } 82 {{- else}} 83 if queries.MustTime(o.{{$colAlias}}).IsZero() { 84 queries.SetScanner(&o.{{$colAlias}}, currTime) 85 } 86 {{- end -}} 87 {{- end -}} 88 {{- if eq $col.Name (or $.AutoColumns.Updated "updated_at") -}} 89 {{- if eq $col.Type "time.Time"}} 90 o.{{$colAlias}} = currTime 91 {{- else}} 92 queries.SetScanner(&o.{{$colAlias}}, currTime) 93 {{- end -}} 94 {{- end -}} 95 {{end}} 96 {{if not .NoContext -}} 97 } 98 {{end -}} 99 {{end}} 100 {{- end}} 101 {{end -}}