Created
October 3, 2025 09:50
-
-
Save kavirajk/9d2a74dc70c325d260d4b836ea2e2fcc to your computer and use it in GitHub Desktop.
withstdasync_sqldb.go
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
| func TestWithStdAsyncDB(t *testing.T) { | |
| conn := clickhouse.OpenDB(&clickhouse.Options{ | |
| Addr: []string{"localhost:9000"}, | |
| Protocol: clickhouse.Native, | |
| }) | |
| ctx := context.Background() | |
| queryID := fmt.Sprintf("%d", time.Now().Unix()) | |
| // queryID := "async-with-opendb" | |
| ctx = clickhouse.Context(ctx, clickhouse.WithStdAsync(true), clickhouse.WithQueryID(queryID)) | |
| _, err := conn.ExecContext(ctx, `DROP TABLE IF EXISTS example`) | |
| require.NoError(t, err) | |
| const ddl = ` | |
| CREATE TABLE example ( | |
| Col1 UInt64 | |
| , Col2 String | |
| , Col3 Array(UInt8) | |
| , Col4 DateTime | |
| ) ENGINE = Memory | |
| ` | |
| _, err = conn.ExecContext(ctx, ddl) | |
| require.NoError(t, err) | |
| for i := 0; i < 100; i++ { | |
| _, err := conn.ExecContext(ctx, `INSERT INTO example VALUES (?, ?, ?, now())`, i, "Golang", []uint8{1, 2, 4}) | |
| require.NoError(t, err) | |
| } | |
| fmt.Println("QueryID", queryID) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you explore this query via
systems.query_log, we can verify it worked with async settings.