bqschema

package module
v0.0.0-...-0cc3af5 Latest Latest
Warning

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

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

README

BQSchema wercker status GoDoc

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 (
	ErrArrayOfArray = errors.New("Array of Arrays not allowed")
	ErrNotStruct    = errors.New("Can not convert non structs")

	ArrayOfArray = ErrArrayOfArray
	NotStruct    = ErrNotStruct
	UnknownType  = errors.New("Unknown type") // no longer used
)

Functions

func MustToSchema

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

MustToSchema panics if conversion to a schema encounters an error.

func ToSchema

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

ToSchema converts the passed type to a BigQuery table schema.

func ToStructs

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

Types

type ErrInconvertibleType

type ErrInconvertibleType struct {
	TypeName string
}

ErrInconvertibleType reports a type that cannot be converted to a BigQuery schema.

func (*ErrInconvertibleType) Error

func (e *ErrInconvertibleType) Error() string

Jump to

Keyboard shortcuts

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