Skip to content

Commit f88afbe

Browse files
Updated doc.go for retrieving query id and connection id (#148)
Added an example to doc.go showing how to register callbacks in the query context to retrieve the connection and query Id.
2 parents ebcd2c2 + 76e0010 commit f88afbe

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

doc.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,36 @@ The result log may look like this:
144144
145145
{"level":"debug","connId":"01ed6545-5669-1ec7-8c7e-6d8a1ea0ab16","corrId":"workflow-example","queryId":"01ed6545-57cc-188a-bfc5-d9c0eaf8e189","time":1668558402,"message":"Run Main elapsed time: 1.298712292s"}
146146
147+
# Programmatically Retrieving Connection and Query Id
148+
149+
Use the driverctx package under driverctx/ctx.go to add callbacks to the query context to receive the connection id and query id.
150+
151+
import (
152+
"github.com/databricks/databricks-sql-go/driverctx"
153+
)
154+
155+
func main() {
156+
157+
...
158+
159+
qidCallback := func(id string) {
160+
fmt.Println("query id: " + id)
161+
}
162+
163+
connIdCallback := func(id string) {
164+
fmt.Println("connection id: " + id)
165+
}
166+
167+
ctx := context.Background()
168+
ctx = driverctx.NewContextWithQueryIdCallback(ctx, qidCallback)
169+
ctx = driverctx.NewContextWithConnIdCallback(ctx, connIdCallback)
170+
171+
rows, err1 := db.QueryContext(ctx, `select * from sometable`)
172+
173+
...
174+
175+
}
176+
147177
# Errors
148178
149179
There are three error types exposed via dbsql/errors

0 commit comments

Comments
 (0)