expr

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 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   = J(Raw(internal.Comma), WriterNewLine)
	CommaWriterSeparator = J(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 AndE

func AndE(expr ...litsql.Expression) litsql.Expression

AndE 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 C

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

C 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 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 ExprIf added in v0.3.2

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

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

func ExprIfElse added in v0.3.6

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

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

func F added in v0.3.6

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

F calls the function to return the expression to output.

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 J

func J(exprs ...litsql.Expression) litsql.Expression

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

func JS

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

JS 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 OrE

func OrE(expr ...litsql.Expression) litsql.Expression

OrE 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 ParenE

func ParenE(expr ...litsql.Expression) litsql.Expression

ParenE 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 S

func S(str string) litsql.Expression

S returns a raw string expression.

func SL

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

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

func SLQ

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

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

func SLQC

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

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

func SQ

func SQ(str string) litsql.Expression

SQ returns a quoted string expression.

func SQC

func SQC(str string) litsql.Expression

SQC 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