sq

package
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgFunc added in v0.3.0

func ArgFunc(fn func() (any, error)) litsql.Argument

ArgFunc returns the argument value in a callback.

func Build added in v0.3.0

func Build(q litsql.Query, options ...BuildOption) (string, []any, error)

Build builds a query string and its arguments.

func DBNamedArg added in v0.5.7

func DBNamedArg(name string, options ...ArgOption) litsql.Argument

DBNamedArg adds a DB-native named argument (for databases that support it). The end value will be wrapped in [sql.Named].

func GetArgValuesInstance added in v0.6.6

func GetArgValuesInstance(values any, options ...GetArgValuesInstanceOption) (litsql.ArgValues, error)

GetArgValuesInstance gets the litsql.ArgValues instance from the passed parameter.

func NamedArg added in v0.5.7

func NamedArg(name string, options ...ArgOption) litsql.Argument

NamedArg adds a named argument for replacement with ParseArgs.

func NewWriter added in v0.3.0

func NewWriter(w io.Writer, options ...WriterOption) litsql.Writer

NewWriter creates the default implementation if litsql.Writer.

func ParseArgValues added in v0.3.3

func ParseArgValues(args []any, values litsql.ArgValues) ([]any, error)

ParseArgValues replaces all litsql.Argument instances in args with named values.

func ParseArgs added in v0.3.0

func ParseArgs(args []any, values any, options ...GetArgValuesInstanceOption) ([]any, error)

ParseArgs replaces all litsql.Argument instances in args with named values.

Types

type ArgOption added in v0.5.7

type ArgOption func(options *argOptions)

func WithDefaultValue added in v0.5.7

func WithDefaultValue(defaultValue any) ArgOption

WithDefaultValue sets a default value if the argument name was not passed.

type ArgsParser added in v0.6.0

type ArgsParser []any

ArgsParser wraps parseable argument results.

func (ArgsParser) Parse added in v0.6.0

func (a ArgsParser) Parse(values any) ([]any, error)

func (ArgsParser) ParseValues added in v0.6.0

func (a ArgsParser) ParseValues(values litsql.ArgValues) ([]any, error)

type BuildOption added in v0.7.0

type BuildOption = internal.BuildQueryOption

func WithGetArgValuesInstanceOptions added in v0.7.0

func WithGetArgValuesInstanceOptions(options ...GetArgValuesInstanceOption) BuildOption

WithGetArgValuesInstanceOptions adds query parse args options.

func WithParseArgValues added in v0.6.0

func WithParseArgValues(argValues litsql.ArgValues) BuildOption

WithParseArgValues adds named argument values.

func WithParseArgs added in v0.6.0

func WithParseArgs(argValues any) BuildOption

WithParseArgs adds named argument values.

func WithWriterOptions added in v0.6.0

func WithWriterOptions(writerOptions ...WriterOption) BuildOption

WithWriterOptions adds writer options.

type BuildQuery added in v0.3.0

type BuildQuery interface {
	Build(options ...BuildOption) (string, []any, error)
}

BuildQuery builds query strings and arguments.

type GetArgValuesInstanceOption added in v0.6.6

type GetArgValuesInstanceOption = internal.GetArgValuesInstanceOption

func WithGetArgValuesInstanceOptionCustom added in v0.6.6

func WithGetArgValuesInstanceOptionCustom(custom func(values any) (litsql.ArgValues, error)) GetArgValuesInstanceOption

WithGetArgValuesInstanceOptionCustom sets a custom litsql.ArgValues detector.

type Handler added in v0.7.0

type Handler interface {
	Build(q litsql.Query, options ...BuildOption) (string, []any, error)
	ParseArgs(args []any, values any, options ...GetArgValuesInstanceOption) ([]any, error)
	ParseArgValues(args []any, values litsql.ArgValues) ([]any, error)
	GetArgValuesInstance(values any, options ...GetArgValuesInstanceOption) (litsql.ArgValues, error)
}

Handler bundles default parameters for functions.

func NewHandler added in v0.7.0

func NewHandler(options ...HandlerOption) Handler

type HandlerOption added in v0.7.0

type HandlerOption func(h *handler)

func WithDefaultBuildOptions added in v0.7.0

func WithDefaultBuildOptions(options ...BuildOption) HandlerOption

WithDefaultBuildOptions sets default options for [Handler.Build].

func WithDefaultGetArgValuesInstanceOptions added in v0.7.0

func WithDefaultGetArgValuesInstanceOptions(options ...GetArgValuesInstanceOption) HandlerOption

WithDefaultGetArgValuesInstanceOptions sets default options for [Handler.ParseArgs] and [Handler.GetArgValuesInstance].

type Mod

type Mod[T, A any] interface {
	ModTag[T]
	Apply(A)
}

Mod is a mod for a generic type.

type ModTag

type ModTag[T any] interface {
	// contains filtered or unexported methods
}

ModTag is used just for interface tagging, so implementations for each dialect aren't accept on others.

type ModTagImpl

type ModTagImpl[T any] struct {
}

type Query

type Query[T any] interface {
	litsql.QueryBuilder
	litsql.Query
	QueryModApply[T]
	BuildQuery
}

Query is the interface for base queries.

type QueryMod

type QueryMod[T any] interface {
	ModTag[T]
	Apply(qb litsql.QueryBuilder)
}

QueryMod is a mod for litsql.QueryBuilder.

func QueryModFunc

func QueryModFunc[T any](f func(apply litsql.QueryBuilder)) QueryMod[T]

type QueryModApply

type QueryModApply[T any] interface {
	Apply(...QueryMod[T])
}

type WriterOption added in v0.3.0

type WriterOption = internal.WriterOption

func WithIndentString added in v0.6.0

func WithIndentString(indentString string) WriterOption

WithIndentString sets the indent string (used only if WithUseNewLine is true). Default is " " (two spaces).

func WithUseNewLine added in v0.6.0

func WithUseNewLine(useNewLine bool) WriterOption

WithUseNewLine sets whether to use newlines in the output or not. Default is true.

Directories

Path Synopsis
reflectxargs module
structargs module

Jump to

Keyboard shortcuts

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