Skip to content

ginokent/bqschema-gen-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bqschema-gen-go

BigQuery table schema Go struct generator

main codecov

generate

How to generate

cd /path/to/your/golang-project-repository

# Create a directory where bqschema-gen-go will generate the code.
mkdir -p bqschema
cd bqschema

# Set GCP Project ID ref. https://console.cloud.google.com/bigquery?p=bigquery-public-data&page=project
export GCLOUD_PROJECT_ID=bigquery-public-data
# Set BigQuery Dataset name ref. https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=hacker_news&page=dataset
export BIGQUERY_DATASET=hacker_news
# Set output file
export OUTPUT_FILE=bqschema.generated.go
# (Option) Set the required environment variables.
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/serviceaccount/keyfile.json

# generate
go run github.com/ginokent/bqschema-gen-go

Example generated file content:

// Code generated by go run github.com/ginokent/bqschema-gen-go; DO NOT EDIT.

//go:generate go run github.com/ginokent/bqschema-gen-go

package bqschema

import "time"

// Comments is BigQuery Table `bigquery-public-data:hacker_news.comments` schema struct.
// Description:
type Comments struct {
	Id      int64     `bigquery:"id"`
	By      string    `bigquery:"by"`
	Author  string    `bigquery:"author"`
	Time    int64     `bigquery:"time"`
	Time_ts time.Time `bigquery:"time_ts"`
	Text    string    `bigquery:"text"`
	Parent  int64     `bigquery:"parent"`
	Deleted bool      `bigquery:"deleted"`
	Dead    bool      `bigquery:"dead"`
	Ranking int64     `bigquery:"ranking"`
}

// Full is BigQuery Table `bigquery-public-data:hacker_news.full` schema struct.
// Description: A full daily update of all the stories and comments in Hacker News.
type Full struct {
	Title       string    `bigquery:"title"`
	Url         string    `bigquery:"url"`
	Text        string    `bigquery:"text"`
	Dead        bool      `bigquery:"dead"`
	By          string    `bigquery:"by"`
	Score       int64     `bigquery:"score"`
	Time        int64     `bigquery:"time"`
	Timestamp   time.Time `bigquery:"timestamp"`
	Type        string    `bigquery:"type"`
	Id          int64     `bigquery:"id"`
	Parent      int64     `bigquery:"parent"`
	Descendants int64     `bigquery:"descendants"`
	Ranking     int64     `bigquery:"ranking"`
	Deleted     bool      `bigquery:"deleted"`
}

// Full_201510 is BigQuery Table `bigquery-public-data:hacker_news.full_201510` schema struct.
// Description:
type Full_201510 struct {
	By          string `bigquery:"by"`
	Score       int64  `bigquery:"score"`
	Time        int64  `bigquery:"time"`
	Title       string `bigquery:"title"`
	Type        string `bigquery:"type"`
	Url         string `bigquery:"url"`
	Text        string `bigquery:"text"`
	Parent      int64  `bigquery:"parent"`
	Deleted     bool   `bigquery:"deleted"`
	Dead        bool   `bigquery:"dead"`
	Descendants int64  `bigquery:"descendants"`
	Id          int64  `bigquery:"id"`
	Ranking     int64  `bigquery:"ranking"`
}

// Stories is BigQuery Table `bigquery-public-data:hacker_news.stories` schema struct.
// Description:
type Stories struct {
	Id          int64     `bigquery:"id"`
	By          string    `bigquery:"by"`
	Score       int64     `bigquery:"score"`
	Time        int64     `bigquery:"time"`
	Time_ts     time.Time `bigquery:"time_ts"`
	Title       string    `bigquery:"title"`
	Url         string    `bigquery:"url"`
	Text        string    `bigquery:"text"`
	Deleted     bool      `bigquery:"deleted"`
	Dead        bool      `bigquery:"dead"`
	Descendants int64     `bigquery:"descendants"`
	Author      string    `bigquery:"author"`
}