-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing timestamppb.Timestamp behind timestamppb tag
- Loading branch information
Showing
8 changed files
with
160 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= | ||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= | ||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= | ||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= | ||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= | ||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= | ||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= | ||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build timestamppb | ||
// +build timestamppb | ||
|
||
// Copyright 2017, 2020 The Godror Authors | ||
// | ||
// | ||
// SPDX-License-Identifier: UPL-1.0 OR Apache-2.0 | ||
|
||
package godror | ||
|
||
import ( | ||
"time" | ||
|
||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
// pbTimestamp is google.golang.org/protobuf/types/known/timestamppb#Timestamp. | ||
type pbTimestamp = timestamppb.Timestamp | ||
|
||
func setPbTimestamp(ts *pbTimestamp, t time.Time) { | ||
*ts = *timestamppb.New(t) | ||
if Log != nil { | ||
Log("msg", "setPbTimestamp", "t", t, "ts", ts) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build !timestamppb | ||
// +build !timestamppb | ||
|
||
// Copyright 2017, 2020 The Godror Authors | ||
// | ||
// | ||
// SPDX-License-Identifier: UPL-1.0 OR Apache-2.0 | ||
|
||
package godror | ||
|
||
import "time" | ||
|
||
// pbTimestamp is a placeholder for google.golang.org/protobuf/types/known/timestamppb#Timestamp. | ||
type pbTimestamp struct{} | ||
|
||
func (ts *pbTimestamp) Reset() { | ||
panic("build with -tags=timestamppb") | ||
} | ||
func (ts *pbTimestamp) AsTime() time.Time { | ||
panic("build with -tags=timestamppb") | ||
} | ||
func (ts *pbTimestamp) IsValid() bool { | ||
panic("build with -tags=timestamppb") | ||
} | ||
|
||
func setPbTimestamp(ts *pbTimestamp, t time.Time) { | ||
panic("build with -tags=timestamppb") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build timestamppb | ||
// +build timestamppb | ||
|
||
package godror_test | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
func TestTimestamppb(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(testContext("Timestamppb"), 30*time.Second) | ||
defer cancel() | ||
const qry = `SELECT SYSDATE, :1, (SYSDATE-:2)*24*3600 FROM DUAL` | ||
it1, it2 := timestamppb.Now(), timestamppb.New(time.Now().Add(-10*time.Minute)) | ||
var ot1, ot2 sql.NullTime | ||
var on3 sql.NullInt64 | ||
if err := testDb.QueryRowContext(ctx, qry, it1, it2).Scan(&ot1, &ot2, &on3); err != nil { | ||
t.Fatalf("%s: %v", qry, err) | ||
} | ||
t.Logf("SYSDATE=%v 1=%v 2=%v", ot1, ot2, on3) | ||
if !(ot2.Valid && !ot2.Time.IsZero()) { | ||
t.Errorf("ot2=%v", ot2) | ||
} | ||
} |