sql

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Args

func (b *Builder) Args() []any

Args returns the positional arguments used in the query.

func (*Builder) Condition

func (b *Builder) Condition(expression string) *Builder

Condition adds a condition to the query. This function accepts a raw expression string. Special characters like '%' do not need to be escaped. Example: Condition("name = '@name'")

func (*Builder) Conditionf

func (b *Builder) Conditionf(format string, args ...any) *Builder

Conditionf adds a condition to the query. This function accepts a format string and arguments, which will be used to create the condition. If the condition uses special characters like '%', they need to be escaped like '%%'. Example: Conditionf("name = '%s'", "John")

func (*Builder) Conditionp

func (b *Builder) Conditionp(lhs, op string, val any) *Builder

Conditionp adds a condition to the query as a positional argument ('$1', '$2'...). lhs is the left-hand side of the condition, op is the operator and val is the value.

Example: Conditionp("name", "=", "John") will be added as "name = '$1'".

func (*Builder) Limit

func (b *Builder) Limit(limit int) *Builder

Limit adds a LIMIT clause to the query.

func (*Builder) Offset

func (b *Builder) Offset(offset int) *Builder

Offset adds an OFFSET clause to the query.

func (*Builder) OrderBy

func (b *Builder) OrderBy(column string, direction OrderDirection) *Builder

func (*Builder) Query

func (b *Builder) Query() string

Query returns the final query string.

func (*Builder) SelectAll

func (b *Builder) SelectAll(table string, alias string) *Builder

SelectAll creates a new query with a SELECT statement which selects all ('*') entities. If an alias is provided, it will be used as the table alias.

type OrderDirection

type OrderDirection string
const (
	OrderByAscending  OrderDirection = "ASC"
	OrderByDescending OrderDirection = "DESC"
)

Jump to

Keyboard shortcuts

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