bqschema

package
v0.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2016 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

README

BQSchema

Documentation: GoDoc
Build Status: Build Status
Test Coverage: Coverage Status

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.

// 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.

// 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()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ArrayOfArray = errors.New("Array of Arrays not allowed")
	UnknownType  = errors.New("Unknown type")
	NotStruct    = errors.New("Can not convert non structs")
)

Functions

func MustToSchema

func MustToSchema(src interface{}) *bigquery.TableSchema

func ToSchema

func ToSchema(src interface{}) (*bigquery.TableSchema, error)

func ToStructs

func ToStructs(result *bigquery.QueryResponse, dst interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL