UTCer
UTCer is a wrapper for database/sql/driver.Driver
that sets time.Time
location to UTC.
Motivation
.UTC()
appears again and again
in projects that store date and time as local timestamp
in UTC.
UTCer mitigates this pain in exchange for inconvenience of timestamp with time zone
.
How It Works
UTCer implements and uses a driver.NamedValueChecker
which replaces Value
of driver.NamedValue
with Value.UTC()
when its type is time.Time
.
Usage
pgx
import (
"database/sql"
_ "github.com/hirofumi/utcer/utcpgx"
)
func open(dsn string) (*sql.DB, error){
return sql.Open("utcpgx", dsn)
}
pq
import (
"database/sql"
_ "github.com/hirofumi/utcer/utcpq"
)
func open(dsn string) (*sql.DB, error){
return sql.Open("utcpq", dsn)
}