expr

package
v1.7.13 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package expr proviedes a simple SQL expression parser and builder. It wraps the rqlite/sql package and provides a more convenient API that contains only what's needed for the go-spacemesh codebase.

Index

Constants

View Source
const (
	NE     = rsql.NE     // !=
	EQ     = rsql.EQ     // =
	LE     = rsql.LE     // <=
	LT     = rsql.LT     // <
	GT     = rsql.GT     // >
	GE     = rsql.GE     // >=
	BITAND = rsql.BITAND // &
	BITOR  = rsql.BITOR  // |
	BITNOT = rsql.BITNOT // !
	LSHIFT = rsql.LSHIFT // <<
	RSHIFT = rsql.RSHIFT // >>
	PLUS   = rsql.PLUS   // +
	MINUS  = rsql.MINUS  // -
	STAR   = rsql.STAR   // *
	SLASH  = rsql.SLASH  // /
	REM    = rsql.REM    // %
	CONCAT = rsql.CONCAT // ||
	DOT    = rsql.DOT    // .
	AND    = rsql.AND
	OR     = rsql.OR
	NOT    = rsql.NOT
)

SQL operations.

Variables

This section is empty.

Functions

func Asc

func Asc(expr Expr) *rsql.OrderingTerm

Asc constructs an ascending ORDER BY term.

func Desc

func Desc(expr Expr) *rsql.OrderingTerm

Desc constructs a descedning ORDER BY term.

func Ident

func Ident(name string) *rsql.Ident

Ident constructs SQL identifier expression for the identifier with the specified name.

func MustParse

func MustParse(s string) rsql.Expr

MustParse parses an SQL expression and panics if there's an error.

func MustParseStatement

func MustParseStatement(s string) rsql.Statement

MustParseStatement parses an SQL statement and panics if there's an error.

func Number

func Number(value string) *rsql.NumberLit

Number constructs a number literal.

func TableSource

func TableSource(name string) rsql.Source

TableSource constructs a Source clause for SELECT statement that corresponds to selecting from a single table with the specified name.

Types

type Expr

type Expr = rsql.Expr

Expr represents a parsed SQL expression.

func Between

func Between(x, a, b Expr) Expr

Between constructs BETWEEN expression: x BETWEEN a AND b.

func Bind

func Bind() Expr

Bind constructs the unnamed bind expression (?).

func Call

func Call(name string, args ...Expr) Expr

Call constructs a call expression with specified arguments such as max(x).

func ColumnExpr

func ColumnExpr(st Statement, n int) Expr

ColumnExpr returns nth column expression from the SELECT statement.

func CountStar

func CountStar() Expr

CountStar returns a COUNT(*) expression.

func MaybeAnd

func MaybeAnd(exprs ...Expr) Expr

MaybeAnd joins together several SQL expressions with AND, ignoring any nil exprs. If no non-nil expressions are passed, nil is returned. If a single non-nil expression is passed, that single expression is returned. Otherwise, the expressions are joined together with ANDs: a AND b AND c AND d.

func Op

func Op(x Expr, op rsql.Token, y Expr) Expr

Op constructs a binary expression such as x + y or x < y.

func WhereExpr

func WhereExpr(st Statement) Expr

WhereExpr returns WHERE expression from the SELECT statement.

type SelectBuilder

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

SelectBuilder is used to construct a SELECT statement.

func Select

func Select(columns ...any) SelectBuilder

Select returns a SELECT statement builder.

func SelectBasedOn

func SelectBasedOn(st Statement) SelectBuilder

SelectBasedOn returns a SELECT statement builder based on the specified SELECT statement. The statement must be parseable, otherwise SelectBasedOn panics. The builder methods can be used to alter the statement.

func (SelectBuilder) Columns

func (sb SelectBuilder) Columns(columns ...any) SelectBuilder

Columns sets columns in the SELECT statement.

func (SelectBuilder) From

From adds FROM clause to the SELECT statement.

func (SelectBuilder) Get

Get returns the underlying SELECT statement.

func (SelectBuilder) Limit

func (sb SelectBuilder) Limit(limit Expr) SelectBuilder

From adds LIMIT clause to the SELECT statement.

func (SelectBuilder) OrderBy

func (sb SelectBuilder) OrderBy(terms ...*rsql.OrderingTerm) SelectBuilder

From adds ORDER BY clause to the SELECT statement.

func (SelectBuilder) String

func (sb SelectBuilder) String() string

String returns the underlying SELECT statement as a string.

func (SelectBuilder) Where

func (sb SelectBuilder) Where(s Expr) SelectBuilder

From adds WHERE clause to the SELECT statement.

type Statement

type Statement = rsql.Statement

Statement represents a parsed SQL statement.

Jump to

Keyboard shortcuts

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