https://github.com/ginokent/bqschema-gen-go
BigQuery table schema Go struct generator
https://github.com/ginokent/bqschema-gen-go
bigquery bigquery-schema gcp gcp-bigquery go golang
Last synced: about 1 year ago
JSON representation
BigQuery table schema Go struct generator
- Host: GitHub
- URL: https://github.com/ginokent/bqschema-gen-go
- Owner: ginokent
- License: mit
- Created: 2020-11-10T16:35:57.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-17T09:51:48.000Z (about 1 year ago)
- Last Synced: 2025-03-31T11:01:38.615Z (about 1 year ago)
- Topics: bigquery, bigquery-schema, gcp, gcp-bigquery, go, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/ginokent/bqschema-gen-go
- Size: 70.3 KB
- Stars: 18
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bqschema-gen-go
BigQuery table schema Go struct generator
[](https://github.com/ginokent/bqschema-gen-go/tree/main)
[](https://codecov.io/gh/ginokent/bqschema-gen-go)
## generate
#### How to generate
```bash
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:
```go
// 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"`
}
```