sqlbuilder

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

sqlbuilder is a builder for SQL statements for clickhouse. copy from https://github.com/huandu/go-sqlbuilder change for chconn

sqlbuilder is a builder for SQL statements for clickhouse. copy from https://github.com/huandu/go-sqlbuilder change for chconn

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(name, alias string) string

As returns an AS expression.

Types

type JoinOption

type JoinOption string

JoinOption is the option in JOIN.

const (
	InnerJoin      JoinOption = "INNER"
	LeftJoin       JoinOption = "LEFT"
	LeftOuterJoin  JoinOption = "LEFT OUTER"
	LeftSemiJoin   JoinOption = "LEFT SEMI"
	LeftAntiJoin   JoinOption = "LEFT ANTI"
	RightJoin      JoinOption = "RIGHT"
	RightOuterJoin JoinOption = "RIGHT OUTER"
	RightSemiJoin  JoinOption = "RIGHT SEMI"
	RightAntiJoin  JoinOption = "RIGHT ANTI"
	FullJoin       JoinOption = "FULL"
	FullOuterJoin  JoinOption = "FULL OUTER"
	CrossJoin      JoinOption = "CROSS"
)

Join options.

type SelectBuilder

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

SelectBuilder is a builder to build SELECT.

func NewSelectBuilder

func NewSelectBuilder() *SelectBuilder

func Select

func Select(col ...string) *SelectBuilder

Select sets columns in SELECT.

func (*SelectBuilder) ArrayJoin

func (sb *SelectBuilder) ArrayJoin(onExpr ...string) *SelectBuilder

arrayJoin sets expressions of Array Join in SELECT.

It builds a ARRAY JOIN expression like

Array JOIN onExpr[0], onExpr[1] ...

func (*SelectBuilder) Build

func (sb *SelectBuilder) Build() (sql string, params *chconn.Parameters)

Build returns compiled SELECT string and args. They can be used in `Select` directly.

func (*SelectBuilder) Column

func (sb *SelectBuilder) Column(col ...string) *SelectBuilder

Select add columns in SELECT.

func (*SelectBuilder) Distinct

func (sb *SelectBuilder) Distinct() *SelectBuilder

Distinct marks this SELECT as DISTINCT.

func (*SelectBuilder) Final

func (sb *SelectBuilder) Final() *SelectBuilder

Final marks this SELECT as FINAL.

func (*SelectBuilder) From

func (sb *SelectBuilder) From(table ...string) *SelectBuilder

From sets table names in SELECT.

func (*SelectBuilder) GroupBy

func (sb *SelectBuilder) GroupBy(col ...string) *SelectBuilder

GroupBy sets columns of GROUP BY in SELECT.

func (*SelectBuilder) Having

func (sb *SelectBuilder) Having(andExpr ...string) *SelectBuilder

Having sets expressions of HAVING in SELECT.

func (*SelectBuilder) Join

func (sb *SelectBuilder) Join(table string, onExpr ...string) *SelectBuilder

Join sets expressions of JOIN in SELECT.

It builds a JOIN expression like

JOIN table ON onExpr[0] AND onExpr[1] ...

func (*SelectBuilder) JoinWithOption

func (sb *SelectBuilder) JoinWithOption(option JoinOption, table string, onExpr ...string) *SelectBuilder

JoinWithOption sets expressions of JOIN with an option.

It builds a JOIN expression like

option JOIN table ON onExpr[0] AND onExpr[1] ...

Here is a list of supported options.

  • FullJoin: FULL JOIN
  • FullOuterJoin: FULL OUTER JOIN
  • InnerJoin: INNER JOIN
  • LeftJoin: LEFT JOIN
  • LeftOuterJoin: LEFT OUTER JOIN
  • RightJoin: RIGHT JOIN
  • RightOuterJoin: RIGHT OUTER JOIN

func (*SelectBuilder) LeftArrayJoin

func (sb *SelectBuilder) LeftArrayJoin() *SelectBuilder

LeftArrayJoin marks this SELECT as LEFT ARRAY JOIN.

func (*SelectBuilder) Limit

func (sb *SelectBuilder) Limit(limit int) *SelectBuilder

Limit sets the LIMIT in SELECT.

func (*SelectBuilder) Offset

func (sb *SelectBuilder) Offset(offset int) *SelectBuilder

Offset sets the LIMIT offset in SELECT.

func (*SelectBuilder) OrderBy

func (sb *SelectBuilder) OrderBy(col ...string) *SelectBuilder

OrderBy sets columns of ORDER BY in SELECT.

func (*SelectBuilder) Parameters

func (sb *SelectBuilder) Parameters(p chconn.Parameter) *SelectBuilder

func (*SelectBuilder) PreWhere

func (sb *SelectBuilder) PreWhere(andExpr ...string) *SelectBuilder

PreWhere sets expressions of PREWHERE in SELECT.

func (*SelectBuilder) SQL

func (sb *SelectBuilder) SQL(sql string) *SelectBuilder

SQL adds an arbitrary sql to current position.

func (*SelectBuilder) Select

func (sb *SelectBuilder) Select(col ...string) *SelectBuilder

Select sets columns in SELECT.

func (*SelectBuilder) String

func (sb *SelectBuilder) String() string

String returns the compiled SELECT string.

func (*SelectBuilder) Where

func (sb *SelectBuilder) Where(andExpr ...string) *SelectBuilder

Where sets expressions of WHERE in SELECT.

Jump to

Keyboard shortcuts

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