Created
May 23, 2023 10:51
-
-
Save puzpuzpuz/bf3282914315aa6fc2fa1bda0e1db2f2 to your computer and use it in GitHub Desktop.
Dynamic column definition in QuestDB Go client
This file contains hidden or 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
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