Skip to content

Instantly share code, notes, and snippets.

@puzpuzpuz
Created May 23, 2023 10:51
Show Gist options
  • Save puzpuzpuz/bf3282914315aa6fc2fa1bda0e1db2f2 to your computer and use it in GitHub Desktop.
Save puzpuzpuz/bf3282914315aa6fc2fa1bda0e1db2f2 to your computer and use it in GitHub Desktop.
Dynamic column definition in QuestDB Go client
package main
import (
"context"
"log"
"strconv"
"time"
qdb "github.com/questdb/go-questdb-client"
)
func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(ctx)
if err != nil {
log.Fatal(err)
}
defer sender.Close()
// Define table for the row.
sender.Table("trades")
// Define symbol columns.
for i := 0; i < 3; i++ {
sender.Symbol("sym"+strconv.Itoa(i), "sym_value")
}
// Define non-symbol columns.
for i := 0; i < 10; i++ {
sender.Float64Column("float"+strconv.Itoa(i), float64(i))
}
// Finally, write the row.
err = sender.At(ctx, time.Now().UnixNano())
if err != nil {
log.Fatal(err)
}
// Make sure that the messages are sent over the network.
err = sender.Flush(ctx)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment