expr

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Space      = Raw(internal.Space)
	CommaSpace = Raw(internal.CommaSpace)
	NewLine    = Raw(internal.NewLine)
	OpenPar    = Raw(internal.OpenPar)
	ClosePar   = Raw(internal.ClosePar)

	CommaWriterNewLine   = Join(Raw(internal.Comma), WriterNewLine)
	CommaWriterSeparator = Join(Raw(internal.Comma), WriterSeparator)
)
View Source
var ErrNoNamedArgs = errors.New("Dialect does not support named arguments")
View Source
var WriterNewLine = litsql.ExpressionFunc(func(w litsql.Writer, d litsql.Dialect, start int) ([]any, error) {
	w.WriteNewLine()
	return nil, nil
})

WriterNewLine calls litsql.Writer.WriteNewline.

View Source
var WriterSeparator = litsql.ExpressionFunc(func(w litsql.Writer, d litsql.Dialect, start int) ([]any, error) {
	w.WriteSeparator()
	return nil, nil
})

WriterSeparator calls litsql.Writer.WriteSeparator.

Functions

func And

func And(expr ...string) litsql.Expression

And outputs the list of expressions separated by " AND ".

func AndExpr added in v0.8.0

func AndExpr(expr ...litsql.Expression) litsql.Expression

AndExpr outputs the list of expressions separated by " AND ".

func Arg

func Arg(value any) litsql.Expression

Arg outputs the dialect-specific argument matcher, and wraps the passed value.

func ArgDBNamed added in v0.6.1

func ArgDBNamed(name string) litsql.Expression

ArgDBNamed outputs the dialect-specific argument matcher, and wraps the passed value as a named argument.

func ArgFunc added in v0.6.1

func ArgFunc(f func() (any, error)) litsql.Expression

ArgFunc returns the argument value in a callback.

func ArgNamed added in v0.5.4

func ArgNamed(name string) litsql.Expression

ArgNamed outputs the dialect-specific argument matcher, and wraps the passed value as a named argument.

func Args

func Args(values []any) []litsql.Expression

Args wraps multiple values in a slice of Arg.

func ArgsDBNamed added in v0.6.1

func ArgsDBNamed(names ...string) []litsql.Expression

ArgsDBNamed wraps multiple values in a slice of ArgDBNamed.

func ArgsFunc added in v0.6.1

func ArgsFunc(fs []func() (any, error)) []litsql.Expression

ArgsFunc wraps multiple values in a slice of ArgFunc.

func ArgsNamed added in v0.5.4

func ArgsNamed(names ...string) []litsql.Expression

ArgsNamed wraps multiple values in a slice of ArgNamed.

func CastSlice

func CastSlice[E litsql.Expression](list []E) []litsql.Expression

CastSlice converts a slice of Expression-implemented items to a slice of litsql.Expression.

func Clause added in v0.8.0

func Clause(query string, args ...any) litsql.Expression

Clause parses the query, replacing any "?" with the dialect-specific argument matcher, and wraps the passed arguments. If the argument is a litsql.Expression, it will be output in-place.

func Func added in v0.8.0

func Func(f func() (litsql.Expression, error)) litsql.Expression

Func calls the function to return the expression to output.

func If added in v0.8.0

func If(condition bool, e litsql.Expression) litsql.Expression

If returns "e" if condition == true, nil otherwise.

func IfElse added in v0.8.0

func IfElse(condition bool, etrue, efalse litsql.Expression) litsql.Expression

IfElse returns "etrue" if condition == true, "efalse" otherwise.

func In

func In(values []any) litsql.Expression

In outputs the list of values as Arg separated by commas.

func InP

func InP(values []any) litsql.Expression

InP outputs the list of values as Arg separated by commas, wrapped in parentheses.

func InPT added in v0.6.4

func InPT[T any](values []T) litsql.Expression

InPT outputs the list of values as Arg separated by commas, wrapped in parentheses.

func InT added in v0.6.4

func InT[T any](values []T) litsql.Expression

InT outputs the list of values as Arg separated by commas.

func Join added in v0.8.0

func Join(exprs ...litsql.Expression) litsql.Expression

Join combines a list of litsql.Expression in a single expression, without a separator.

func JoinSep added in v0.8.0

func JoinSep(sep string, exprs ...litsql.Expression) litsql.Expression

JoinSep combines a list of litsql.Expression in a single expression, using the passed separator.

func MapSlice added in v0.6.1

func MapSlice[T any](source []T, mapFunc func(T) litsql.Expression) []litsql.Expression

MapSlice converts a slice of data to a slice of litsql.Expression using a map function.

func Or

func Or(expr ...string) litsql.Expression

Or outputs the list of expressions separated by " OR ".

func OrExpr added in v0.8.0

func OrExpr(expr ...litsql.Expression) litsql.Expression

OrExpr outputs the list of expressions separated by " OR ".

func Paren

func Paren(expr ...string) litsql.Expression

Paren returns an expression what outputs the list of expressions comma-separated with parenthesis around.

func ParenExpr added in v0.8.0

func ParenExpr(expr ...litsql.Expression) litsql.Expression

ParenExpr returns an expression what outputs the list of expressions comma-separated with parenthesis around.

func PrefixIf added in v0.3.2

func PrefixIf(condition bool, prefix litsql.Expression, e litsql.Expression) litsql.Expression

PrefixIf returns an expression with the passed prefix if condition == true, only the expression if false.

func Quote

func Quote(aa ...string) litsql.Expression

Quote outputs quoted and joined, something like "users"."id".

func QuoteCheck

func QuoteCheck(aa ...string) litsql.Expression

QuoteCheck outputs quoted and joined, something like "users"."id", only if each string needs to be quoted.

func String added in v0.8.0

func String(str string) litsql.Expression

String returns a raw string expression.

func StringList added in v0.8.0

func StringList(str []string) []litsql.Expression

StringList converts a slice of strings to a slice of raw string expressions.

func StringListQuote added in v0.8.0

func StringListQuote(str []string) []litsql.Expression

StringListQuote converts a slice of strings to a slice of quoted raw string expressions.

func StringListQuoteCheck added in v0.8.0

func StringListQuoteCheck(str []string) []litsql.Expression

StringListQuoteCheck converts a slice of strings to a slice of checked quoted raw string expressions.

func StringQuote added in v0.8.0

func StringQuote(str string) litsql.Expression

StringQuote returns a quoted string expression.

func StringQuoteCheck added in v0.8.0

func StringQuoteCheck(str string) litsql.Expression

StringQuoteCheck returns a checked quoted string expression (only quote if needed).

func WriterAddSeparator

func WriterAddSeparator(topLevel bool) litsql.Expression

WriterAddSeparator calls litsql.Writer.AddSeparator.

Types

type Raw

type Raw string

Raw is an litsql.Expression that outputs the string itself as-is.

func (Raw) WriteSQL

func (r Raw) WriteSQL(w litsql.Writer, d litsql.Dialect, start int) ([]any, error)

Jump to

Keyboard shortcuts

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