compare

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package compare provides shared SQL fragments for dialect statement compilers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileBoolEqual

func CompileBoolEqual[F ~uint8, T any](w Writer, filter *database.CompareFilter[F], schema database.Schema[F, T]) bool

CompileBoolEqual compiles a single-term equality against a bool constant as the bare (negated) expression. Planners convert a bare EXISTS / NOT EXISTS into a semi/anti-join but evaluate `EXISTS (...) = $1` per row. Reports whether the filter was handled.

func CompileCorrelated

func CompileCorrelated[F ~uint8, T any](
	w Writer,
	filter *database.CorrelatedFilter[F],
	schema database.Schema[F, T],
	writeValue func(Writer, any, database.Column[F]),
)

CompileCorrelated compiles a database.CorrelatedFilter by writing the column's computed expression around the bound value: SQLName, the value, then SQLSuffix. Every dialect emits the same shape, so the only per-dialect difference is the schema binding's text and the placeholder writeValue emits.

func CompileNullAware

func CompileNullAware[F ~uint8, T any](
	w Writer,
	filter *database.CompareFilter[F],
	schema database.Schema[F, T],
	writeValue func(Writer, any, database.Column[F]),
)

CompileNullAware expands compares whose terms bind SQL NULL or cover nullable keyset columns. Requires ASC NULLS FIRST / DESC NULLS LAST: postgres and sqlite state it explicitly in ORDER BY for nullable columns, spanner rejects the clause but guarantees that ordering by default. writeValue emits a bound placeholder (and any dialect cast) for non-nil values.

func NeedsNullAware

func NeedsNullAware[F ~uint8, T any](filter *database.CompareFilter[F], schema database.Schema[F, T]) bool

NeedsNullAware reports whether a compare must use null-safe expansion: any term binds SQL NULL, or a keyset compare touches a nullable column (a non-nil cursor value must still admit NULL rows beyond the cursor).

func WriteNullsOrder

func WriteNullsOrder[F ~uint8, T any](w Writer, column database.Column[F], direction database.OrderDirection, schema database.Schema[F, T])

WriteNullsOrder states the NULL position CompileNullAware assumes: ASC NULLS FIRST / DESC NULLS LAST. Emitted only for nullable columns, because on a NOT NULL column the clause changes nothing semantically but stops postgres from matching the default index order (index scan degrades to a full sort). Spanner rejects the clause and guarantees this ordering by default, so its compiler must not call this.

Types

type Writer

type Writer interface {
	WriteString(string)
}

Writer is the minimal surface for emitting SQL text fragments.

Jump to

Keyboard shortcuts

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