Skip to content

Commit e8d780a

Browse files
authored
feat(client): introduce safer timestamp API (#23)
1 parent b7519bf commit e8d780a

11 files changed

+309
-147
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![GoDoc reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/questdb/go-questdb-client)
1+
[![GoDoc reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/questdb/go-questdb-client/v2)
22

33
# go-questdb-client
44

@@ -8,9 +8,9 @@ Features:
88
* Context-aware API.
99
* Optimized for batch writes.
1010
* Supports TLS encryption and [ILP authentication](https://questdb.io/docs/reference/api/ilp/authenticate).
11-
* Tested against QuestDB 6.4.1 and newer versions.
11+
* Tested against QuestDB 7.3.2 and newer versions.
1212

13-
Documentation is available [here](https://pkg.go.dev/github.com/questdb/go-questdb-client).
13+
Documentation is available [here](https://pkg.go.dev/github.com/questdb/go-questdb-client/v2).
1414

1515
## Usage
1616

@@ -23,7 +23,7 @@ import (
2323
"log"
2424
"time"
2525

26-
qdb "github.com/questdb/go-questdb-client"
26+
qdb "github.com/questdb/go-questdb-client/v2"
2727
)
2828

2929
func main() {

examples.manifest.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
lang: go
55
path: examples/basic/main.go
66
header: |-
7-
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client)
7+
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client/v2)
88
and [repo](https://github.com/questdb/go-questdb-client).
99
- name: ilp-auth
1010
lang: go
1111
path: examples/auth/main.go
1212
header: |-
13-
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client)
13+
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client/v2)
1414
and [repo](https://github.com/questdb/go-questdb-client).
1515
auth:
1616
kid: testUser1
@@ -22,7 +22,7 @@
2222
lang: go
2323
path: examples/auth-and-tls/main.go
2424
header: |-
25-
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client)
25+
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client/v2)
2626
and [repo](https://github.com/questdb/go-questdb-client).
2727
auth:
2828
kid: testUser1

examples/auth-and-tls/main.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"time"
77

8-
qdb "github.com/questdb/go-questdb-client"
8+
qdb "github.com/questdb/go-questdb-client/v2"
99
)
1010

1111
func main() {
@@ -14,32 +14,48 @@ func main() {
1414
ctx,
1515
qdb.WithAddress("localhost:9009"),
1616
qdb.WithAuth(
17-
"testUser1",
18-
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48"),
17+
"testUser1", // token name here
18+
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
19+
),
1920
qdb.WithTls(),
2021
)
2122
if err != nil {
2223
log.Fatal(err)
2324
}
2425
// Make sure to close the sender on exit to release resources.
2526
defer sender.Close()
27+
2628
// Send a few ILP messages.
29+
bday, err := time.Parse(time.DateOnly, "1856-07-10")
30+
if err != nil {
31+
log.Fatal(err)
32+
}
2733
err = sender.
28-
Table("trades").
29-
Symbol("name", "test_ilp1").
30-
Float64Column("value", 12.4).
31-
At(ctx, time.Now().UnixNano())
34+
Table("inventors").
35+
Symbol("born", "Austrian Empire").
36+
TimestampColumn("birthdate", bday). // Epoch in micros.
37+
Int64Column("id", 0).
38+
StringColumn("name", "Nicola Tesla").
39+
At(ctx, time.Now()) // Epoch in nanos.
40+
if err != nil {
41+
log.Fatal(err)
42+
}
43+
44+
bday, err = time.Parse(time.DateOnly, "1847-02-11")
3245
if err != nil {
3346
log.Fatal(err)
3447
}
3548
err = sender.
36-
Table("trades").
37-
Symbol("name", "test_ilp2").
38-
Float64Column("value", 11.4).
39-
At(ctx, time.Now().UnixNano())
49+
Table("inventors").
50+
Symbol("born", "USA").
51+
TimestampColumn("birthdate", bday).
52+
Int64Column("id", 1).
53+
StringColumn("name", "Thomas Alva Edison").
54+
AtNow(ctx)
4055
if err != nil {
4156
log.Fatal(err)
4257
}
58+
4359
// Make sure that the messages are sent over the network.
4460
err = sender.Flush(ctx)
4561
if err != nil {

examples/auth/main.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"time"
77

8-
qdb "github.com/questdb/go-questdb-client"
8+
qdb "github.com/questdb/go-questdb-client/v2"
99
)
1010

1111
func main() {
@@ -14,31 +14,47 @@ func main() {
1414
ctx,
1515
qdb.WithAddress("localhost:9009"),
1616
qdb.WithAuth(
17-
"testUser1",
18-
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48"),
17+
"testUser1", // token name here
18+
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
19+
),
1920
)
2021
if err != nil {
2122
log.Fatal(err)
2223
}
2324
// Make sure to close the sender on exit to release resources.
2425
defer sender.Close()
26+
2527
// Send a few ILP messages.
28+
bday, err := time.Parse(time.DateOnly, "1856-07-10")
29+
if err != nil {
30+
log.Fatal(err)
31+
}
2632
err = sender.
27-
Table("trades").
28-
Symbol("name", "test_ilp1").
29-
Float64Column("value", 12.4).
30-
At(ctx, time.Now().UnixNano())
33+
Table("inventors").
34+
Symbol("born", "Austrian Empire").
35+
TimestampColumn("birthdate", bday). // Epoch in micros.
36+
Int64Column("id", 0).
37+
StringColumn("name", "Nicola Tesla").
38+
At(ctx, time.Now()) // Epoch in nanos.
39+
if err != nil {
40+
log.Fatal(err)
41+
}
42+
43+
bday, err = time.Parse(time.DateOnly, "1847-02-11")
3144
if err != nil {
3245
log.Fatal(err)
3346
}
3447
err = sender.
35-
Table("trades").
36-
Symbol("name", "test_ilp2").
37-
Float64Column("value", 11.4).
38-
At(ctx, time.Now().UnixNano())
48+
Table("inventors").
49+
Symbol("born", "USA").
50+
TimestampColumn("birthdate", bday).
51+
Int64Column("id", 1).
52+
StringColumn("name", "Thomas Alva Edison").
53+
AtNow(ctx)
3954
if err != nil {
4055
log.Fatal(err)
4156
}
57+
4258
// Make sure that the messages are sent over the network.
4359
err = sender.Flush(ctx)
4460
if err != nil {

examples/basic/main.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"time"
77

8-
qdb "github.com/questdb/go-questdb-client"
8+
qdb "github.com/questdb/go-questdb-client/v2"
99
)
1010

1111
func main() {
@@ -17,23 +17,38 @@ func main() {
1717
}
1818
// Make sure to close the sender on exit to release resources.
1919
defer sender.Close()
20+
2021
// Send a few ILP messages.
22+
bday, err := time.Parse(time.DateOnly, "1856-07-10")
23+
if err != nil {
24+
log.Fatal(err)
25+
}
2126
err = sender.
22-
Table("trades").
23-
Symbol("name", "test_ilp1").
24-
Float64Column("value", 12.4).
25-
At(ctx, time.Now().UnixNano())
27+
Table("inventors").
28+
Symbol("born", "Austrian Empire").
29+
TimestampColumn("birthdate", bday). // Epoch in micros.
30+
Int64Column("id", 0).
31+
StringColumn("name", "Nicola Tesla").
32+
At(ctx, time.Now()) // Epoch in nanos.
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
bday, err = time.Parse(time.DateOnly, "1847-02-11")
2638
if err != nil {
2739
log.Fatal(err)
2840
}
2941
err = sender.
30-
Table("trades").
31-
Symbol("name", "test_ilp2").
32-
Float64Column("value", 11.4).
33-
At(ctx, time.Now().UnixNano())
42+
Table("inventors").
43+
Symbol("born", "USA").
44+
TimestampColumn("birthdate", bday).
45+
Int64Column("id", 1).
46+
StringColumn("name", "Thomas Alva Edison").
47+
AtNow(ctx)
3448
if err != nil {
3549
log.Fatal(err)
3650
}
51+
3752
// Make sure that the messages are sent over the network.
3853
err = sender.Flush(ctx)
3954
if err != nil {

go.mod

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,63 @@
1-
module github.com/questdb/go-questdb-client
1+
module github.com/questdb/go-questdb-client/v2
22

33
go 1.17
44

55
require (
6-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
7-
github.com/Microsoft/go-winio v0.4.17 // indirect
8-
github.com/Microsoft/hcsshim v0.8.23 // indirect
9-
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
10-
github.com/containerd/cgroups v1.0.1 // indirect
11-
github.com/containerd/containerd v1.5.9 // indirect
6+
github.com/stretchr/testify v1.8.4
7+
github.com/testcontainers/testcontainers-go v0.25.0
8+
)
9+
10+
require (
11+
dario.cat/mergo v1.0.0 // indirect
12+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
13+
github.com/Microsoft/go-winio v0.6.1 // indirect
14+
github.com/Microsoft/hcsshim v0.11.1 // indirect
15+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
16+
github.com/containerd/cgroups v1.1.0 // indirect
17+
github.com/containerd/containerd v1.7.6 // indirect
18+
github.com/cpuguy83/dockercfg v0.3.1 // indirect
1219
github.com/davecgh/go-spew v1.1.1 // indirect
13-
github.com/docker/distribution v2.7.1+incompatible // indirect
14-
github.com/docker/docker v20.10.11+incompatible // indirect
20+
github.com/distribution/reference v0.5.0 // indirect
21+
github.com/docker/distribution v2.8.3+incompatible // indirect
22+
github.com/docker/docker v24.0.6+incompatible // indirect
1523
github.com/docker/go-connections v0.4.0 // indirect
16-
github.com/docker/go-units v0.4.0 // indirect
24+
github.com/docker/go-units v0.5.0 // indirect
25+
github.com/go-ole/go-ole v1.3.0 // indirect
1726
github.com/gogo/protobuf v1.3.2 // indirect
18-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
19-
github.com/golang/protobuf v1.5.2 // indirect
20-
github.com/google/uuid v1.3.0 // indirect
21-
github.com/magiconair/properties v1.8.5 // indirect
22-
github.com/moby/sys/mount v0.2.0 // indirect
23-
github.com/moby/sys/mountinfo v0.5.0 // indirect
24-
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
25-
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
27+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
28+
github.com/golang/protobuf v1.5.3 // indirect
29+
github.com/google/uuid v1.3.1 // indirect
30+
github.com/klauspost/compress v1.17.0 // indirect
31+
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
32+
github.com/magiconair/properties v1.8.7 // indirect
33+
github.com/moby/patternmatcher v0.6.0 // indirect
34+
github.com/moby/sys/mount v0.3.3 // indirect
35+
github.com/moby/sys/mountinfo v0.6.2 // indirect
36+
github.com/moby/sys/sequential v0.5.0 // indirect
37+
github.com/moby/term v0.5.0 // indirect
38+
github.com/morikuni/aec v1.0.0 // indirect
2639
github.com/opencontainers/go-digest v1.0.0 // indirect
27-
github.com/opencontainers/image-spec v1.0.2 // indirect
28-
github.com/opencontainers/runc v1.0.2 // indirect
40+
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
41+
github.com/opencontainers/runc v1.1.9 // indirect
2942
github.com/pkg/errors v0.9.1 // indirect
3043
github.com/pmezard/go-difflib v1.0.0 // indirect
31-
github.com/sirupsen/logrus v1.8.1 // indirect
32-
github.com/stretchr/objx v0.2.0 // indirect
33-
github.com/stretchr/testify v1.7.1 // indirect
34-
github.com/testcontainers/testcontainers-go v0.13.0 // indirect
35-
go.opencensus.io v0.22.3 // indirect
36-
golang.org/x/net v0.0.0-20211108170745-6635138e15ea // indirect
37-
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect
38-
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
39-
google.golang.org/grpc v1.33.2 // indirect
40-
google.golang.org/protobuf v1.27.1 // indirect
41-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
44+
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
45+
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
46+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
47+
github.com/sirupsen/logrus v1.9.3 // indirect
48+
github.com/stretchr/objx v0.5.0 // indirect
49+
github.com/tklauser/go-sysconf v0.3.12 // indirect
50+
github.com/tklauser/numcpus v0.6.1 // indirect
51+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
52+
go.opencensus.io v0.24.0 // indirect
53+
golang.org/x/exp v0.0.0-20231005195138-3e424a577f31 // indirect
54+
golang.org/x/mod v0.13.0 // indirect
55+
golang.org/x/net v0.16.0 // indirect
56+
golang.org/x/sys v0.13.0 // indirect
57+
golang.org/x/tools v0.14.0 // indirect
58+
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
59+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
60+
google.golang.org/grpc v1.58.2 // indirect
61+
google.golang.org/protobuf v1.31.0 // indirect
62+
gopkg.in/yaml.v3 v3.0.1 // indirect
4263
)

0 commit comments

Comments
 (0)