Skip to content

bonitoo-io/go-sql-bigquery

 
 

Repository files navigation

BigQuery SQL Driver for Golang

This is an implementation of the BigQuery Client as a database/sql/driver for easy integration and usage.

Goals of project

This project is meant to be a basic database/sql driver implementation for Golang so that developers can easily use *sql.DB functions with Google's BigQuery database.

Unlike the original project, this driver

  • does not contain ORM extension
  • uses different connection string

Connection string

The connection string format is URL with bigquery scheme and host representing project ID. Path (optional) represents location (cloud region).

  • bigquery://projectid/?param1=value&param2=value
  • bigquery://projectid/location?param1=value&param2=value

Common parameters

  • dataset - dataset ID. When set, it allows to use unqualified tables names in queries.

Authentication parameters

As this is using the Google Cloud Go SDK, you will need to have your credentials available via the GOOGLE_APPLICATION_CREDENTIALS environment variable point to your credential JSON file.

Alternatively, you can use one of the following parameters:

  • apiKey - API key value
  • credentials - base-64 encoded service account or refresh token JSON credentials

Examples:

  • bigquery://projectid/?apiKey=AIzaSyB6XK8IO5AzKZXoioQOVNTFYzbDBjY5hy4
  • bigquery://projectid/?credentials=eyJ0eXBlIjoiYXV0...

Usage

package main

import "github.com/bonitoo-io/go-sql-bigquery"

func main() {
    db, err := sql.Open("bigquery", "bigquery://lunar-1234/?dataset=storeys")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close() 
    ...
}

Contribution

Contributions are welcome.

Current Support

  • driver.Conn implemented
  • driver.Querier implemented
  • driver.Pinger implemented
  • driver.DriverContext implemented
  • driver.QueryerContext implemented
  • driver.ExecerContext implemented
  • driver.RowsColumnTypeDatabaseTypeName implemented
  • Prepared Statements - supported via a quick hack
  • Parameterized Queries

About

Go database/sql driver for Google BigQuery

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%