Skip to content

Commit

Permalink
Add current timestamp pg function const
Browse files Browse the repository at this point in the history
  • Loading branch information
perrito666 committed Jul 4, 2018
1 parent 946e869 commit f1851df
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions db/chain/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ package chain

import "fmt"

// NullValue represents the NULL value in SQL
const NullValue = "NULL"
const (
// NullValue represents the NULL value in SQL
NullValue = "NULL"
// CurrentTimestampPGFn is the name of the function of postgres that returns current
// timestamp with tz.
CurrentTimestampPGFn = "CURRENT_TIMESTAMP"
)

// Constraint wraps the passed constraint name with the required SQL to use it.
func Constraint(constraint string) string {
Expand Down Expand Up @@ -96,5 +101,5 @@ func Null(field string) string {
// SetToCurrentTimestamp crafts a postgres SQL assignement of the field to the current timestamp
// with timezone.
func SetToCurrentTimestamp(field string) string {
return fmt.Sprintf("%s = CURRENT_TIMESTAMP", field)
return fmt.Sprintf("%s = %s", field, CurrentTimestampPGFn)
}

0 comments on commit f1851df

Please sign in to comment.