-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
50 lines (42 loc) · 1.29 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package bigquery
import (
"database/sql/driver"
"cloud.google.com/go/bigquery"
)
// GetJob is a type of function that can be passed as an argument to a Query or
// Exec method to get a handle on the BigQuery job for the query (e.g. to get
// its statistics after the query completes). The function will be called with
// a [bigquery.Job] value before the Query/Exec method returns.
type GetJob func(job *bigquery.Job)
// GetQuery is a type of function that can be passed as an argument to a Query
// or Exec method to get a handle on the BigQuery query before it's executed
// (e.g. to execute a dry run). The function will be called with a
// [bigquery.Query] value before the Query/Exec method returns.
type GetQuery func(query *bigquery.Query)
type options struct {
getQuery GetQuery
getJob GetJob
}
func (o *options) CheckNamedValue(named *driver.NamedValue) error {
switch value := named.Value.(type) {
case GetQuery:
o.getQuery = value
return driver.ErrRemoveArgument
case GetJob:
o.getJob = value
return driver.ErrRemoveArgument
}
return driver.ErrSkip
}
func (o *options) getQueryOpt(query *bigquery.Query) {
if o.getQuery != nil {
o.getQuery(query)
o.getQuery = nil
}
}
func (o *options) getJobOpt(job *bigquery.Job) {
if o.getJob != nil {
o.getJob(job)
o.getJob = nil
}
}