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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# BQSchema
**Documentation:** [](http://godoc.org/github.com/SeanDolphin/bqschema)
**Build Status:** [](https://travis-ci.org/SeanDolphin/bqschema)
**Test Coverage:** [](https://coveralls.io/r/SeanDolphin/bqschema)
BQSchema is a package used to created Google Big Query schema directly from Go structs and import BigQuery QueryResponse into arrays of Go structs.
## Usage
You can use BQSchema to automatically load Google Big Query results into arrays of basic Go structs.
~~~ go
// main.go
package main
import (
"google.golang.org/api/bigquery/v2"
"github.com/SeanDolphin/bqschema"
)
type person struct{
Name string
Email string
Age int
}
func main() {
// authorize the bigquery service
// create a query
result, err := bq.Jobs.Query("projectID", query).Do()
if err == nil {
var people []person
err := bqschema.ToStructs(result, &people)
// do something with people
}
}
~~~
You can also use BQSchema to create the schema fields when creating new Big Query tables from basic Go structs.
~~~ go
// main.go
package main
import (
"google.golang.org/api/bigquery/v2"
"github.com/SeanDolphin/bqschema"
)
type person struct{
Name string
Email string
Age int
}
func main() {
// authorize the bigquery service
table, err := bq.Tables.Insert("projectID","datasetID", bigquery.Table{
Schema:bqschema.MustToSchema(person{})
}).Do()
}
~~~
|