spannerbuilder

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 7 Imported by: 0

README

spannerbuilder

spanner sql builder for select statements

supported methods
  • Select
    • Syntax: .Select(statement, col1, col2, ...)
    • .Select("field_name") // special case, same as .Select("field_name", "field_name")
    • .Select("DISTINCT field_name", "field_name")
    • .Select("COUNT(*)", "field_name")
    • .Select("field_name1, field_name2", "field_name1", "field_name2")
    • .Select("field_name1").Select("field_name2") // only field_name2 will be selected
  • Join
    • .Join("table_name USING(field_name)")
    • .Join("table_name USING(field_name)", "LEFT OUTER")
    • .Join("table_name USING(field_name)", "RIGHT", "OUTER")
    • .Join("table_name USING(field_name)").Join("table_name USING(field_name)")
    • .Join("table_name1@{FORCE_INDEX=index_name} ON table_name1.field_name = table_name2.field_name")
  • Index
    • .Index("index_name")
  • OrderBy
    • .OrderBy("field_name")
    • .OrderBy("field_name DESC")
  • Where
    • .Where("field_name <op> ?", varName)
    • .Where("field_name <op> @field_name", map[string]interface{}{"field_name": verName})
  • GroupBy
    • .Select("Sum(field_name1), field_name2", "field_name1", "field_name2"). GroupBy("group_by_expression")
  • Having (with GroupBy, Select)
    • .Select("Sum(field_name1), field_name2", "field_name1", "field_name2"). GroupBy("group_by_expression").Having("SUM(field_name1) > 0")
    • .Select("Sum(field_name1), field_name2", "field_name1", "field_name2"). GroupBy("group_by_expression").Having("SUM(field_name1) > ?", 1)
    • .Select("Sum(field_name1), field_name2", "field_name1", "field_name2"). GroupBy("group_by_expression").Having("SUM(field_name1) > @param0", map[string]interface{}{"param0": 1})
    • Having (with GroupBy, Select, Where)
      • .Select("Sum(field_name1), field_name2", "field_name1", "field_name2"). Where("field_name2 == ?", "something"). GroupBy("group_by_expression").Having("SUM(field_name1) > @param0", map[string]interface{}{"param0": 1})
  • Limit
    • .Limit(20)
  • Offset (with Limit)
    • .Limit(20).Offset(10)
  • From
    • .From("table_name")
    • .From("table_name@{FORCE_INDEX=index_name}")
  • TableSample
    • .TableSample("RESERVOIR (100 ROWS)"),
    • .TableSample("BERNOULLI (0.1 PERCENT)")
  • Statement
    • .Statement("SELECT * FROM users WHERE user_id = ?", "test")
    • .Statement("SELECT * FROM users WHERE user_id = '{0}'", "test")
    • .Statement("SELECT * FROM users WHERE user_id IN ({0}, {1})", 1, 2)
    • .Statement("SELECT * FROM users WHERE user_id = @userId", map[string]interface{}{"userId": "test"})
    • .Statement("SELECT * FROM users WHERE user_id = '{userId}'", map[string]interface{}{"userId": "test"})
SQL Logging
  • set DB_DEBUG=1 to output SQL Log

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDeleteSQL added in v0.1.6

func GetDeleteSQL(table string, keys []string, values []interface{}) spanner.Statement

func GetInsertOrIgnoreSQL added in v0.2.0

func GetInsertOrIgnoreSQL(table string, cols, keys []string, values []interface{}) spanner.Statement

func GetInsertOrUpdateSQL added in v0.2.0

func GetInsertOrUpdateSQL(table string, cols, keys []string, values []interface{}) spanner.Statement

func GetInsertSQL added in v0.1.4

func GetInsertSQL(table string, cols, keys []string, values []interface{}) spanner.Statement

func GetUpdateSQL added in v0.1.4

func GetUpdateSQL(table string, cols, keys []string, values []interface{}) spanner.Statement

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewSpannerBuilder

func NewSpannerBuilder(table string, cols, keys []string, args ...map[string]interface{}) *Builder

func (*Builder) Columns

func (b *Builder) Columns() []string

func (*Builder) From

func (b *Builder) From(s string, args ...interface{}) *Builder

func (*Builder) GetSelectStatement

func (b *Builder) GetSelectStatement() spanner.Statement

func (*Builder) GroupBy

func (b *Builder) GroupBy(s string) *Builder

func (*Builder) Having

func (b *Builder) Having(s string, args ...interface{}) *Builder

func (*Builder) Index added in v0.0.2

func (b *Builder) Index(index string) *Builder

func (*Builder) Join

func (b *Builder) Join(s string, args ...interface{}) *Builder

func (*Builder) Limit

func (b *Builder) Limit(i int) *Builder

func (*Builder) Offset added in v0.0.3

func (b *Builder) Offset(i int) *Builder

func (*Builder) OrderBy

func (b *Builder) OrderBy(s string, args ...interface{}) *Builder

func (*Builder) Params added in v0.0.11

func (b *Builder) Params(args map[string]interface{}) *Builder

func (*Builder) Select

func (b *Builder) Select(s string, args ...interface{}) *Builder

func (*Builder) SetColumns added in v0.1.0

func (b *Builder) SetColumns(cols ...string) *Builder

func (*Builder) SetTableFieldMap added in v0.1.2

func (b *Builder) SetTableFieldMap(m map[string][]string) *Builder

func (*Builder) Statement added in v0.0.8

func (b *Builder) Statement(sql string, args ...interface{}) *Builder

func (*Builder) String added in v0.0.11

func (b *Builder) String() string

func (*Builder) TableSample

func (b *Builder) TableSample(s string) *Builder

func (*Builder) Union added in v0.0.11

func (b *Builder) Union(sel Selector, unionTypes ...string) *Builder

func (*Builder) Where

func (b *Builder) Where(s string, args ...interface{}) *Builder

func (*Builder) WhereIf added in v0.1.3

func (b *Builder) WhereIf(cond bool, s string, args ...interface{}) *Builder

type Selector added in v0.0.11

type Selector interface {
	GetSelectStatement() spanner.Statement
}

Jump to

Keyboard shortcuts

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