Skip to content

Commit a562658

Browse files
authored
chore(docs): meaningful example (#36)
1 parent 38fdfc7 commit a562658

File tree

5 files changed

+69
-66
lines changed

5 files changed

+69
-66
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*.so
66
*.dylib
77

8+
# MacOS debris
9+
.DS_Store
10+
811
# Test binary, built with `go test -c`
912
*.test
1013

@@ -16,3 +19,4 @@
1619

1720
# IDEs
1821
.vscode/*
22+
.idea

examples/from-conf/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
qdb "github.com/questdb/go-questdb-client/v3"
99
)
1010

11-
const dateOnly = "2006-01-02"
12-
1311
func main() {
1412
ctx := context.TODO()
1513
sender, err := qdb.LineSenderFromConf(ctx, "http::addr=localhost:9000;")
@@ -25,32 +23,34 @@ func main() {
2523
}()
2624

2725
// Send a few ILP messages.
28-
bday, err := time.Parse(dateOnly, "1856-07-10")
26+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
2927
if err != nil {
3028
log.Fatal(err)
3129
}
3230
err = sender.
33-
Table("inventors_go").
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.
31+
Table("trades_go").
32+
Symbol("pair", "USDGBP").
33+
Symbol("type", "buy").
34+
Float64Column("traded_price", 0.83).
35+
Float64Column("limit_price", 0.84).
36+
Int64Column("qty", 100).
37+
At(ctx, tradedTs)
3938
if err != nil {
4039
log.Fatal(err)
4140
}
4241

43-
bday, err = time.Parse(dateOnly, "1847-02-11")
42+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
4443
if err != nil {
4544
log.Fatal(err)
4645
}
4746
err = sender.
48-
Table("inventors_go").
49-
Symbol("born", "USA").
50-
TimestampColumn("birthdate", bday).
51-
Int64Column("id", 1).
52-
StringColumn("name", "Thomas Alva Edison").
53-
AtNow(ctx)
47+
Table("trades_go").
48+
Symbol("pair", "GBPJPY").
49+
Symbol("type", "sell").
50+
Float64Column("traded_price", 135.97).
51+
Float64Column("limit_price", 0.84).
52+
Int64Column("qty", 400).
53+
At(ctx, tradedTs)
5454
if err != nil {
5555
log.Fatal(err)
5656
}

examples/http/auth-and-tls/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
qdb "github.com/questdb/go-questdb-client/v3"
99
)
1010

11-
const dateOnly = "2006-01-02"
12-
1311
func main() {
1412
ctx := context.TODO()
1513
sender, err := qdb.NewLineSender(
@@ -33,32 +31,34 @@ func main() {
3331
}()
3432

3533
// Send a few ILP messages.
36-
bday, err := time.Parse(dateOnly, "1856-07-10")
34+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
3735
if err != nil {
3836
log.Fatal(err)
3937
}
4038
err = sender.
41-
Table("inventors_go").
42-
Symbol("born", "Austrian Empire").
43-
TimestampColumn("birthdate", bday). // Epoch in micros.
44-
Int64Column("id", 0).
45-
StringColumn("name", "Nicola Tesla").
46-
At(ctx, time.Now()) // Epoch in nanos.
39+
Table("trades_go").
40+
Symbol("pair", "USDGBP").
41+
Symbol("type", "buy").
42+
Float64Column("traded_price", 0.83).
43+
Float64Column("limit_price", 0.84).
44+
Int64Column("qty", 100).
45+
At(ctx, tradedTs)
4746
if err != nil {
4847
log.Fatal(err)
4948
}
5049

51-
bday, err = time.Parse(dateOnly, "1847-02-11")
50+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
5251
if err != nil {
5352
log.Fatal(err)
5453
}
5554
err = sender.
56-
Table("inventors_go").
57-
Symbol("born", "USA").
58-
TimestampColumn("birthdate", bday).
59-
Int64Column("id", 1).
60-
StringColumn("name", "Thomas Alva Edison").
61-
AtNow(ctx)
55+
Table("trades_go").
56+
Symbol("pair", "GBPJPY").
57+
Symbol("type", "sell").
58+
Float64Column("traded_price", 135.97).
59+
Float64Column("limit_price", 0.84).
60+
Int64Column("qty", 400).
61+
At(ctx, tradedTs)
6262
if err != nil {
6363
log.Fatal(err)
6464
}

examples/http/auth/main.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package main
22

33
import (
44
"context"
5+
qdb "github.com/questdb/go-questdb-client/v3"
56
"log"
67
"time"
7-
8-
qdb "github.com/questdb/go-questdb-client/v3"
98
)
109

11-
const dateOnly = "2006-01-02"
12-
1310
func main() {
1411
ctx := context.TODO()
1512
sender, err := qdb.NewLineSender(
@@ -33,32 +30,34 @@ func main() {
3330
}()
3431

3532
// Send a few ILP messages.
36-
bday, err := time.Parse(dateOnly, "1856-07-10")
33+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
3734
if err != nil {
3835
log.Fatal(err)
3936
}
4037
err = sender.
41-
Table("inventors_go").
42-
Symbol("born", "Austrian Empire").
43-
TimestampColumn("birthdate", bday). // Epoch in micros.
44-
Int64Column("id", 0).
45-
StringColumn("name", "Nicola Tesla").
46-
At(ctx, time.Now()) // Epoch in nanos.
38+
Table("trades_go").
39+
Symbol("pair", "USDGBP").
40+
Symbol("type", "buy").
41+
Float64Column("traded_price", 0.83).
42+
Float64Column("limit_price", 0.84).
43+
Int64Column("qty", 100).
44+
At(ctx, tradedTs)
4745
if err != nil {
4846
log.Fatal(err)
4947
}
5048

51-
bday, err = time.Parse(dateOnly, "1847-02-11")
49+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
5250
if err != nil {
5351
log.Fatal(err)
5452
}
5553
err = sender.
56-
Table("inventors_go").
57-
Symbol("born", "USA").
58-
TimestampColumn("birthdate", bday).
59-
Int64Column("id", 1).
60-
StringColumn("name", "Thomas Alva Edison").
61-
AtNow(ctx)
54+
Table("trades_go").
55+
Symbol("pair", "GBPJPY").
56+
Symbol("type", "sell").
57+
Float64Column("traded_price", 135.97).
58+
Float64Column("limit_price", 0.84).
59+
Int64Column("qty", 400).
60+
At(ctx, tradedTs)
6261
if err != nil {
6362
log.Fatal(err)
6463
}

examples/http/basic/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
qdb "github.com/questdb/go-questdb-client/v3"
99
)
1010

11-
const dateOnly = "2006-01-02"
12-
1311
func main() {
1412
ctx := context.TODO()
1513
// Connect to QuestDB running on 127.0.0.1:9009
@@ -26,32 +24,34 @@ func main() {
2624
}()
2725

2826
// Send a few ILP messages.
29-
bday, err := time.Parse(dateOnly, "1856-07-10")
27+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
3028
if err != nil {
3129
log.Fatal(err)
3230
}
3331
err = sender.
34-
Table("inventors_go").
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.
32+
Table("trades_go").
33+
Symbol("pair", "USDGBP").
34+
Symbol("type", "buy").
35+
Float64Column("traded_price", 0.83).
36+
Float64Column("limit_price", 0.84).
37+
Int64Column("qty", 100).
38+
At(ctx, tradedTs)
4039
if err != nil {
4140
log.Fatal(err)
4241
}
4342

44-
bday, err = time.Parse(dateOnly, "1847-02-11")
43+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
4544
if err != nil {
4645
log.Fatal(err)
4746
}
4847
err = sender.
49-
Table("inventors_go").
50-
Symbol("born", "USA").
51-
TimestampColumn("birthdate", bday).
52-
Int64Column("id", 1).
53-
StringColumn("name", "Thomas Alva Edison").
54-
AtNow(ctx)
48+
Table("trades_go").
49+
Symbol("pair", "GBPJPY").
50+
Symbol("type", "sell").
51+
Float64Column("traded_price", 135.97).
52+
Float64Column("limit_price", 0.84).
53+
Int64Column("qty", 400).
54+
At(ctx, tradedTs)
5555
if err != nil {
5656
log.Fatal(err)
5757
}

0 commit comments

Comments
 (0)