Documentation ¶
Overview ¶
Package bq provides definitions and methods for structs used for querying data from the a dataset on BigQuery
Index ¶
- func Fetch(ctx context.Context, sb SelectBuilder) (*bigquery.RowIterator, error)
- func In(field string, values ...string) string
- func JExtract(json string, path string) string
- func Like(field string, values ...string) string
- func NotIn(field string, values ...string) string
- func NotLike(field string, values ...string) string
- type Columns
- type Pair
- type SelectBuilder
- func (b SelectBuilder) And(conditions ...string) SelectBuilder
- func (b SelectBuilder) From(names ...string) SelectBuilder
- func (b SelectBuilder) IsEmpty() bool
- func (b SelectBuilder) Limit(limit uint64) SelectBuilder
- func (b SelectBuilder) Or(conditions ...string) SelectBuilder
- func (b SelectBuilder) OrderBy(fields ...string) SelectBuilder
- func (b SelectBuilder) SQL() (string, error)
- func (b SelectBuilder) Select(cols Columns, args ...string) SelectBuilder
- func (b SelectBuilder) SelectAll() SelectBuilder
- func (b SelectBuilder) Where(condition string) SelectBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fetch ¶
func Fetch(ctx context.Context, sb SelectBuilder) (*bigquery.RowIterator, error)
Fetch executes a BigQuery Job using the supplied context, SelectBuilder and returns a row iterator with results.
func JExtract ¶
JExtract formats a Column in a select query to use JSON_EXTRACT_SCALAR As per https://cloud.google.com/bigquery/docs/reference/legacy-sql#json_extract_scalar
Example: JExtract('payload','action') ==> JSON_EXTRACT_SCALAR(payload,'$.action')
Types ¶
type Pair ¶
Pair stores key value pairs that are used in various methods of the builder
The syntax results in a statement like "Select html_url as url" in traditional SQL
type SelectBuilder ¶
SelectBuilder is an exported Builder that allows users to build Legacy SQL queries on BigQuery
func Debug ¶
func Debug(t SelectBuilder) SelectBuilder
func Select ¶
func Select(c Columns, args ...string) SelectBuilder
Select acts as wrapper to easily start a new SelectBuilder Chain
func (SelectBuilder) And ¶
func (b SelectBuilder) And(conditions ...string) SelectBuilder
And adds all strings in conditions to b.Conditions with an "AND" prefix
func (SelectBuilder) From ¶
func (b SelectBuilder) From(names ...string) SelectBuilder
From adds all strings in names to use as tables in the query
func (SelectBuilder) IsEmpty ¶
func (b SelectBuilder) IsEmpty() bool
IsEmpty checks if the builder has any fields and returns true or false
func (SelectBuilder) Limit ¶
func (b SelectBuilder) Limit(limit uint64) SelectBuilder
Limit adds a limit clause to the query
func (SelectBuilder) Or ¶
func (b SelectBuilder) Or(conditions ...string) SelectBuilder
Or adds all strings in conditions to b.Conditions with an "OR" prefix
func (SelectBuilder) OrderBy ¶
func (b SelectBuilder) OrderBy(fields ...string) SelectBuilder
OrderBy adds all strings in fields to b.SortFields separated by spaces
func (SelectBuilder) SQL ¶
func (b SelectBuilder) SQL() (string, error)
SQL composes the query string to use with BigQuery's Legacy SQL standard
func (SelectBuilder) Select ¶
func (b SelectBuilder) Select(cols Columns, args ...string) SelectBuilder
Select adds field and label from Columns{Pair{Key: field, Value: label)} to the list columns to select
For Example: Select({'html_url': 'url'}) results in SELECT html_url url
Select also supports JSON Extracted field names - by passing the path as Column key and JSON field name as second argument
func (SelectBuilder) SelectAll ¶
func (b SelectBuilder) SelectAll() SelectBuilder
SelectAll sets Fields in the selectComponents to "*", which results in a "SELECT * FROM..." like query
func (SelectBuilder) Where ¶
func (b SelectBuilder) Where(condition string) SelectBuilder
Where adds condition to the b.Condition. If previous conditions exist, it behaves like b.And(condition)