frag

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alias

func Alias(table, column string) string

Alias generates a deterministic alias name for a given table and column. If the combined length is shorter than 64 characters (minus separators), it returns a simple "table__column" alias. Otherwise, it generates a hashed form using a cached SHA1-based abbreviation to keep the alias short and stable.

func Collect

func Collect(ctx context.Context, f Fragment) (string, []any)

func IsNil

func IsNil(e Fragment) bool

IsNil returns if a Fragment is nil

func NonNil

func NonNil[F Fragment](seq iter.Seq[F]) iter.Seq[Fragment]

NonNil filter nil fragments

Types

type CustomValueArg

type CustomValueArg interface {
	ValueEx() string
}

CustomValueArg supports replacing ? to some sql snippet eg: ? => UPPER(?)

type Fragment

type Fragment interface {
	IsNil() bool
	Frag(ctx context.Context) Iter
}

Fragment defines an interface to present a sql fragment

func Arg

func Arg(v any) Fragment

Arg presents a single argument fragment

func ArgIterFunc

func ArgIterFunc(v any) Fragment

func Block

func Block(f Fragment) Fragment

Block returns a bracketed Fragment eg:

select ... from ... => (select ... from ...)

func BlockWithoutBrackets

func BlockWithoutBrackets(seq iter.Seq[Fragment]) Fragment

func Compose

func Compose(sep string, frags ...Fragment) Fragment

func ComposeSeq

func ComposeSeq(sep string, frags iter.Seq[Fragment]) Fragment

func Empty

func Empty() Fragment

func Func

func Func(f func(context.Context) Iter) Fragment

func Lit

func Lit(q string) Fragment

func Query

func Query(query string, args ...any) Fragment

type Iter

type Iter = iter.Seq2[string, []any]

Iter will yield a SQL fragment with a raw query(string with holder) and values eg:

query = INSERT INTO t_table (f_x,f_y,f_z) VALUES (?,?,?)
args  = 1, '2', 3.0

func ArgIter

func ArgIter(ctx context.Context, v any) Iter

type NamedArg

type NamedArg = sql.NamedArg

type NamedArgs

type NamedArgs map[string]any

type Values

type Values[T any] iter.Seq[T]

func (Values[T]) Frag

func (vs Values[T]) Frag(_ context.Context) Iter

func (Values[T]) IsNil

func (vs Values[T]) IsNil() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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