litsql

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: MIT Imports: 6 Imported by: 5

README

litsql - Literal SQL query builder

Author

Rangel Reale (rangelreale@gmail.com)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(q Query, writerOptions ...WriterOption) (string, []any, error)

func Express

func Express(w Writer, d Dialect, start int, e Expression) ([]any, error)

func ExpressIf

func ExpressIf(w Writer, d Dialect, start int, e Expression, cond bool, prefix, suffix Expression) ([]any, error)

ExpressIf expands an express if the condition evaluates to true it can also add a prefix and suffix

func ExpressSlice

func ExpressSlice(w Writer, d Dialect, start int, expressions []Expression, prefix, sep, suffix Expression) ([]any, error)

ExpressSlice is used to express a slice of expressions along with a prefix and suffix

func ParseArgs

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

Types

type ArgValues

type ArgValues interface {
	Get(string) (any, bool)
}

type Argument

type Argument interface {
	// contains filtered or unexported methods
}

func Arg

func Arg(name string) Argument

func ArgDefault

func ArgDefault(name string, defaultValue any) Argument

func ArgFunc

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

type ArgumentBase

type ArgumentBase struct{}

type BuildQuery

type BuildQuery interface {
	Build(writerOptions ...WriterOption) (string, []any, error)
}

type DBNamedArgument

type DBNamedArgument interface {
	Argument
	DBName() string
}

func DBArg

func DBArg(name string) DBNamedArgument

type Dialect

type Dialect interface {
	WriteArg(w Writer, position int)
	WriteQuoted(w Writer, s string)
	WriteCheckQuoted(w Writer, s string)
}

type DialectWithNamed

type DialectWithNamed interface {
	Dialect
	WriteNamedArg(w Writer, name string)
}

type ExpressBuilder

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

ExpressBuilder builds arguments in a sequence of Express calls.

func NewExpressBuilder

func NewExpressBuilder(w Writer, d Dialect, start int) *ExpressBuilder

func (*ExpressBuilder) Err

func (h *ExpressBuilder) Err() error

func (*ExpressBuilder) Express

func (h *ExpressBuilder) Express(e Expression)

func (*ExpressBuilder) ExpressIf

func (h *ExpressBuilder) ExpressIf(e Expression, cond bool, prefix, suffix Expression)

func (*ExpressBuilder) ExpressSlice

func (h *ExpressBuilder) ExpressSlice(expressions []Expression, prefix, sep, suffix Expression)

func (*ExpressBuilder) Result

func (h *ExpressBuilder) Result() ([]any, error)

func (*ExpressBuilder) WriteQuery

func (h *ExpressBuilder) WriteQuery(e Query)

type Expression

type Expression interface {
	WriteSQL(w Writer, d Dialect, start int) (args []any, err error)
}

type ExpressionFunc

type ExpressionFunc func(w Writer, d Dialect, start int) ([]any, error)

func (ExpressionFunc) WriteSQL

func (e ExpressionFunc) WriteSQL(w Writer, d Dialect, start int) ([]any, error)

type MapArgValues

type MapArgValues map[string]any

func (MapArgValues) Get

func (m MapArgValues) Get(s string) (any, bool)

type NamedArgument

type NamedArgument interface {
	Argument
	Name() string
}

type Query

type Query interface {
	Expression
	WriteQuery(w Writer, start int) (args []any, err error)
}

type QueryBuilder

type QueryBuilder interface {
	Dialect() Dialect
	Add(q QueryClause)
}

type QueryClause

type QueryClause interface {
	Expression
	ClauseOrder() int
}

type QueryClauseMerge

type QueryClauseMerge interface {
	QueryClause
	ClauseMerge(other QueryClause)
}

type QueryClauseMultiple

type QueryClauseMultiple interface {
	QueryClause
	ClauseMultiple()
}

type QueryClauseWrapper

type QueryClauseWrapper interface {
	WrappedQueryClause() QueryClause
}

type ValuedArgument

type ValuedArgument interface {
	Argument
	Value() (any, error)
}

type Writer

type Writer interface {
	Write(s string)
	WriteNewLine()
	WriteSeparator()
	AddSeparator(topLevel bool)
	StartQuery()
	Indent()
	Dedent()
	Err() error
}

func NewWriter

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

type WriterOption

type WriterOption func(*writer)

func WithWriterIndentStr

func WithWriterIndentStr(indentStr string) WriterOption

func WithWriterUseNewLine

func WithWriterUseNewLine(useNewLine bool) WriterOption

Jump to

Keyboard shortcuts

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