conds

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 2 Imported by: 0

README

conds

CI Go Reference GitHub tag (latest by date)

cond is a tiny builder of where clause conditions.

Installation

go get github.com/winebarrel/conds

Usage

package main

import (
	"fmt"

	c "github.com/winebarrel/conds"
)

func main() {
	n := 100
	s := "foo"
	var nilstr *string
	var nilnum *int

	w := c.
		C("num = @n", c.V("n", n)).
		AND_C("str = @s", c.V("s", s)).
		// XV: Null value conditions are removed
		AND_C("sval = @ns", c.XV("ns", nilstr)).

	stmt, params := w.StmtParams()

	fmt.Println(stmt)   //=> "num = @n AND str = @s"
	fmt.Println(params) //=> map[n:100 nn:<nil> s:foo]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IF

func IF[T any](expr bool, cthen, celse T) T

func IFF added in v0.5.0

func IFF[T any](expr bool, f func() T) T

func IFTHEN added in v0.6.0

func IFTHEN[T any](expr bool, cthen T) T

func StmtParams added in v0.8.0

func StmtParams[T ~map[string]any](c Condition) (string, T)

Types

type Condition

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

func AND

func AND(conditions ...Condition) Condition

func C

func C(stmt string, nvs ...NamedValue) Condition

func Empty

func Empty() Condition

func NonNil added in v0.3.0

func NonNil[T any](param *T, f func(T) Condition) Condition

func NonZero added in v0.7.0

func NonZero[T comparable](param T, f func(T) Condition) Condition

func OR

func OR(others ...Condition) Condition

func (Condition) AND

func (c Condition) AND(other Condition) Condition

func (Condition) AND_C

func (c Condition) AND_C(stmt string, nvs ...NamedValue) Condition

func (Condition) Empty

func (c Condition) Empty() bool

func (Condition) Enclose

func (c Condition) Enclose() Condition

func (Condition) OR

func (c Condition) OR(other Condition) Condition

func (Condition) OR_C

func (c Condition) OR_C(stmt string, nvs ...NamedValue) Condition

func (Condition) StmtParams

func (c Condition) StmtParams() (string, map[string]any)

type NamedValue

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

func V added in v0.9.0

func V(name string, value any) NamedValue

func VMap added in v0.9.0

func VMap(m map[string]any) []NamedValue

func XV added in v0.9.0

func XV[T any](name string, value *T) NamedValue

Jump to

Keyboard shortcuts

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