sqlbuilder

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqlbuilder contains functionality for building SQL from the AST.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseOps

func BaseOps() map[string]string

BaseOps returns a default map of SLQ operator (e.g. "==" or "!=") to its default SQL rendering. The returned map is a copy and can be safely modified by the caller.

Types

type BaseFragmentBuilder

type BaseFragmentBuilder struct {
	Log lg.Log
	// Quote is the driver-specific quote rune, e.g. " or `
	Quote    string
	ColQuote string
	Ops      map[string]string
}

BaseFragmentBuilder is a default implementation of sqlbuilder.FragmentBuilder.

func (*BaseFragmentBuilder) Expr

func (fb *BaseFragmentBuilder) Expr(expr *ast.Expr) (string, error)

Expr implements FragmentBuilder.

func (*BaseFragmentBuilder) FromTable

func (fb *BaseFragmentBuilder) FromTable(tblSel *ast.TblSelector) (string, error)

FromTable implements FragmentBuilder.

func (*BaseFragmentBuilder) Function

func (fb *BaseFragmentBuilder) Function(fn *ast.Func) (string, error)

Function implements FragmentBuilder.

func (*BaseFragmentBuilder) Join

func (fb *BaseFragmentBuilder) Join(fnJoin *ast.Join) (string, error)

Join implements FragmentBuilder.

func (*BaseFragmentBuilder) Operator

func (fb *BaseFragmentBuilder) Operator(op *ast.Operator) (string, error)

Operator implements FragmentBuilder.

func (*BaseFragmentBuilder) Range

func (fb *BaseFragmentBuilder) Range(rr *ast.RowRange) (string, error)

Range implements FragmentBuilder.

func (*BaseFragmentBuilder) SelectAll

func (fb *BaseFragmentBuilder) SelectAll(tblSel *ast.TblSelector) (string, error)

SelectAll implements FragmentBuilder.

func (*BaseFragmentBuilder) SelectCols

func (fb *BaseFragmentBuilder) SelectCols(cols []ast.ColExpr) (string, error)

SelectCols implements FragmentBuilder.

func (*BaseFragmentBuilder) Where

func (fb *BaseFragmentBuilder) Where(where *ast.Where) (string, error)

Where implements FragmentBuilder.

type BaseQueryBuilder

type BaseQueryBuilder struct {
	SelectClause  string
	FromClause    string
	WhereClause   string
	RangeClause   string
	OrderByClause string
}

BaseQueryBuilder is a default implementation of sqlbuilder.QueryBuilder.

func (*BaseQueryBuilder) SQL

func (qb *BaseQueryBuilder) SQL() (string, error)

SQL implements QueryBuilder.

func (*BaseQueryBuilder) SetFrom

func (qb *BaseQueryBuilder) SetFrom(from string)

SetFrom implements QueryBuilder.

func (*BaseQueryBuilder) SetRange

func (qb *BaseQueryBuilder) SetRange(rng string)

SetRange implements QueryBuilder.

func (*BaseQueryBuilder) SetSelect

func (qb *BaseQueryBuilder) SetSelect(cols string)

SetSelect implements QueryBuilder.

func (*BaseQueryBuilder) SetWhere

func (qb *BaseQueryBuilder) SetWhere(where string)

SetWhere implements QueryBuilder.

type FragmentBuilder

type FragmentBuilder interface {
	// FromTable renders a FROM table fragment.
	FromTable(tblSel *ast.TblSelector) (string, error)

	// SelectCols renders a column names/expression fragment.
	SelectCols(cols []ast.ColExpr) (string, error)

	// SelectAll renders a SELECT * fragment.
	SelectAll(tblSel *ast.TblSelector) (string, error)

	// Range renders a row range fragment.
	Range(rr *ast.RowRange) (string, error)

	// Join renders a join fragment.
	Join(fnJoin *ast.Join) (string, error)

	// Function renders a function fragment.
	Function(fn *ast.Func) (string, error)

	// Where renders a WHERE fragment.
	Where(where *ast.Where) (string, error)

	// Expr renders an expression fragment.
	Expr(expr *ast.Expr) (string, error)

	// Operator renders an operator fragment.
	Operator(op *ast.Operator) (string, error)
}

FragmentBuilder renders driver-specific SQL fragments.

type QueryBuilder

type QueryBuilder interface {
	// SetSelect sets the columns to select.
	SetSelect(cols string)

	// SetFrom sets the FROM clause.
	SetFrom(from string)

	// SetWhere sets the WHERE clause.
	SetWhere(where string)

	// SetRange sets the range clause.
	SetRange(rng string)

	// SQL renders the SQL query.
	SQL() (string, error)
}

QueryBuilder provides an abstraction for building a SQL query.

Jump to

Keyboard shortcuts

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