astql

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 5 Imported by: 0

README

astql

CI Coverage Go Report Card CodeQL Go Reference License Go Version Release

Type-safe SQL query builder with DBML schema validation.

Build queries as an AST, validate against your schema, render to parameterized SQL.

Injection-safe SQL Expressions, Any Dialect

instance.T("users")      // ✓ exists in schema
instance.T("uusers")     // panic: table "uusers" not found

instance.F("email")      // ✓ exists in schema
instance.F("emial")      // panic: field "emial" not found

query := astql.Select(instance.T("users")).
    Fields(instance.F("username"), instance.F("email")).
    Where(instance.C(instance.F("active"), astql.EQ, instance.P("is_active")))

result, _ := query.Render(postgres.New())
// SELECT "username", "email" FROM "users" WHERE "active" = :is_active

Typos become compile-time failures, not runtime surprises. Values are parameterized. Identifiers are quoted. The schema is the source of truth.

Same query, different databases:

import (
    "github.com/zoobzio/astql/postgres"
    "github.com/zoobzio/astql/sqlite"
    "github.com/zoobzio/astql/mariadb"
    "github.com/zoobzio/astql/mssql"
)

result, _ := query.Render(postgres.New())  // "username", LIMIT 10
result, _ := query.Render(sqlite.New())    // "username", LIMIT 10
result, _ := query.Render(mariadb.New())   // `username`, LIMIT 10
result, _ := query.Render(mssql.New())     // [username], TOP 10

One AST. Four dialects. Each renderer handles identifier quoting, pagination syntax, vendor-specific operators.

Install

go get github.com/zoobzio/astql
go get github.com/zoobzio/dbml

Requires Go 1.24+.

Quick Start

package main

import (
    "fmt"
    "github.com/zoobzio/astql"
    "github.com/zoobzio/astql/postgres"
    "github.com/zoobzio/dbml"
)

func main() {
    // Define schema
    project := dbml.NewProject("myapp")
    users := dbml.NewTable("users")
    users.AddColumn(dbml.NewColumn("id", "bigint"))
    users.AddColumn(dbml.NewColumn("username", "varchar"))
    users.AddColumn(dbml.NewColumn("email", "varchar"))
    users.AddColumn(dbml.NewColumn("active", "boolean"))
    project.AddTable(users)

    // Create instance
    instance, err := astql.NewFromDBML(project)
    if err != nil {
        panic(err)
    }

    // Build and render
    result, err := astql.Select(instance.T("users")).
        Fields(instance.F("username"), instance.F("email")).
        Where(instance.C(instance.F("active"), astql.EQ, instance.P("is_active"))).
        OrderBy(instance.F("username"), astql.ASC).
        Limit(10).
        Render(postgres.New())

    if err != nil {
        panic(err)
    }

    fmt.Println(result.SQL)
    // SELECT "username", "email" FROM "users" WHERE "active" = :is_active ORDER BY "username" ASC LIMIT 10
    fmt.Println(result.RequiredParams)
    // [is_active]
}

Capabilities

Feature Description Docs
Schema Validation Tables and fields checked against DBML at build time Schema Validation
Multi-Dialect PostgreSQL, SQLite, MariaDB, MSSQL from one AST Architecture
Parameterized Values Injection-resistant queries with named parameters Conditions
Composable Queries Subqueries, JOINs, aggregates, window functions Joins
CASE Expressions Conditional logic within queries API

Why ASTQL?

  • Schema-validatedT("users") and F("email") checked against DBML at build time
  • Injection-resistant — parameterized values, quoted identifiers, no string concatenation
  • Multi-dialect — one query, four databases
  • Composable — subqueries, JOINs, aggregates, window functions, CASE expressions

Schema-First Data Access

ASTQL enables a pattern: define schema once in DBML, generate everything else.

Your DBML becomes the single source of truth. Downstream tools consume the schema to build:

  • Type-safe repositories — generated data access layers with cereal
  • Query builders — domain-specific methods that can't reference invalid columns
  • Multi-database applications — same business logic, swappable storage backends
// Schema defines what's valid
project := dbml.ParseFile("schema.dbml")
instance, _ := astql.NewFromDBML(project)

// Queries are structurally correct by construction
users := instance.T("users")
query := astql.Select(users).
    Fields(instance.F("id"), instance.F("email")).
    Where(instance.C(instance.F("active"), astql.EQ, instance.P("active")))

// Render to any supported database
sql, _ := query.Render(postgres.New())  // production
sql, _ := query.Render(sqlite.New())    // testing

The schema guards the boundary. Queries inside the boundary are safe by construction.

Documentation

Learn
  • Quickstart — get started in minutes
  • Concepts — tables, fields, params, conditions, builders
  • Architecture — AST structure, render pipeline, security layers
Guides
  • Schema Validation — DBML integration and validation
  • Conditions — WHERE, AND/OR, subqueries, BETWEEN
  • Joins — INNER, LEFT, RIGHT, CROSS joins
  • Aggregates — GROUP BY, HAVING, window functions
  • Testing — testing patterns for query builders
Cookbook
Reference
  • API — complete function documentation
  • Operators — all comparison and special operators

Contributing

See CONTRIBUTING.md for guidelines. For security issues, see SECURITY.md.

License

MIT — see LICENSE.

Documentation

Overview

Package astql provides a type-safe SQL query builder with multi-provider support.

The package generates an Abstract Syntax Tree (AST) from fluent builder calls, then renders it to SQL with named parameters compatible with sqlx. Schema validation is available through DBML integration.

Basic Usage

Queries can be built directly using the package-level builder functions:

import "github.com/zoobzio/astql/postgres"

query := astql.Select(table).
	Fields(field1, field2).
	Where(condition).
	OrderBy(field1, astql.ASC).
	Limit(10)

result, err := query.Render(postgres.New())
// result.SQL: SELECT "field1", "field2" FROM "table" WHERE ... ORDER BY "field1" ASC LIMIT 10
// result.RequiredParams: []string{"param_name", ...}

Multi-Provider Support

The package supports multiple SQL dialects through the Renderer interface. Available providers: postgres, mariadb, sqlite, mssql.

import "github.com/zoobzio/astql/mariadb"

result, err := query.Render(mariadb.New())

Schema-Validated Usage

For compile-time safety, create an ASTQL instance from a DBML schema:

instance, err := astql.NewFromDBML(project)
if err != nil {
	return err
}

// These panic if the field/table doesn't exist in the schema
users := instance.T("users")
email := instance.F("email")

Supported Operations

The package supports SELECT, INSERT, UPDATE, DELETE, and COUNT operations, along with JOINs, subqueries, window functions, aggregates, CASE expressions, set operations (UNION, INTERSECT, EXCEPT), and PostgreSQL-specific features like DISTINCT ON, row locking, RETURNING, ON CONFLICT, and pgvector operators.

Output Format

All queries use named parameters (`:param_name`) for use with sqlx.NamedExec and similar functions. Identifiers are quoted to handle reserved words.

Index

Constants

View Source
const (
	OpSelect = types.OpSelect
	OpInsert = types.OpInsert
	OpUpdate = types.OpUpdate
	OpDelete = types.OpDelete
	OpCount  = types.OpCount
)

Re-export operation constants for public API.

View Source
const (
	ASC  = types.ASC
	DESC = types.DESC
)

Re-export direction constants for public API.

View Source
const (
	NullsFirst = types.NullsFirst
	NullsLast  = types.NullsLast
)

Re-export nulls ordering constants for public API.

View Source
const (
	// Basic comparison operators.
	EQ = types.EQ
	NE = types.NE
	GT = types.GT
	GE = types.GE
	LT = types.LT
	LE = types.LE

	// Extended operators.
	IN        = types.IN
	NotIn     = types.NotIn
	LIKE      = types.LIKE
	NotLike   = types.NotLike
	ILIKE     = types.ILIKE
	NotILike  = types.NotILike
	IsNull    = types.IsNull
	IsNotNull = types.IsNotNull
	EXISTS    = types.EXISTS
	NotExists = types.NotExists

	// Regex operators (PostgreSQL).
	RegexMatch     = types.RegexMatch
	RegexIMatch    = types.RegexIMatch
	NotRegexMatch  = types.NotRegexMatch
	NotRegexIMatch = types.NotRegexIMatch

	// Array operators (PostgreSQL).
	ArrayContains    = types.ArrayContains
	ArrayContainedBy = types.ArrayContainedBy
	ArrayOverlap     = types.ArrayOverlap

	// Vector operators (pgvector).
	VectorL2Distance     = types.VectorL2Distance
	VectorInnerProduct   = types.VectorInnerProduct
	VectorCosineDistance = types.VectorCosineDistance
	VectorL1Distance     = types.VectorL1Distance
)

Re-export operator constants for public API.

View Source
const (
	AggSum           = types.AggSum
	AggAvg           = types.AggAvg
	AggMin           = types.AggMin
	AggMax           = types.AggMax
	AggCountField    = types.AggCountField
	AggCountDistinct = types.AggCountDistinct
)

Re-export aggregate function constants for public API.

View Source
const (
	CastText            = types.CastText
	CastInteger         = types.CastInteger
	CastBigint          = types.CastBigint
	CastSmallint        = types.CastSmallint
	CastNumeric         = types.CastNumeric
	CastReal            = types.CastReal
	CastDoublePrecision = types.CastDoublePrecision
	CastBoolean         = types.CastBoolean
	CastDate            = types.CastDate
	CastTime            = types.CastTime
	CastTimestamp       = types.CastTimestamp
	CastTimestampTZ     = types.CastTimestampTZ
	CastInterval        = types.CastInterval
	CastUUID            = types.CastUUID
	CastJSON            = types.CastJSON
	CastJSONB           = types.CastJSONB
	CastBytea           = types.CastBytea
)

Re-export cast type constants for public API.

View Source
const (
	WinRowNumber  = types.WinRowNumber
	WinRank       = types.WinRank
	WinDenseRank  = types.WinDenseRank
	WinNtile      = types.WinNtile
	WinLag        = types.WinLag
	WinLead       = types.WinLead
	WinFirstValue = types.WinFirstValue
	WinLastValue  = types.WinLastValue
)

Re-export window function constants for public API.

View Source
const (
	FrameUnboundedPreceding = types.FrameUnboundedPreceding
	FrameCurrentRow         = types.FrameCurrentRow
	FrameUnboundedFollowing = types.FrameUnboundedFollowing
)

Re-export frame bound constants for public API.

View Source
const (
	SetUnion        = types.SetUnion
	SetUnionAll     = types.SetUnionAll
	SetIntersect    = types.SetIntersect
	SetIntersectAll = types.SetIntersectAll
	SetExcept       = types.SetExcept
	SetExceptAll    = types.SetExceptAll
)

Re-export set operation constants for public API.

Variables

This section is empty.

Functions

func Abs added in v0.0.6

func Abs(field types.Field) types.FieldExpression

Abs creates an ABS math expression.

func As added in v0.0.6

As adds an alias to a field expression.

func Avg added in v0.0.6

func Avg(field types.Field) types.FieldExpression

Avg creates an AVG aggregate expression.

func AvgFilter added in v0.0.14

func AvgFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

AvgFilter creates an AVG aggregate with a FILTER clause.

func Between added in v0.0.14

func Between(field types.Field, low, high types.Param) types.BetweenCondition

Example: Between(field, low, high) -> field BETWEEN :low AND :high.

func BinaryExpr added in v1.0.4

func BinaryExpr(field types.Field, op types.Operator, param types.Param) types.FieldExpression

BinaryExpr creates a binary expression for field <op> param patterns. Commonly used for vector distance calculations, e.g., embedding <-> :query Example: BinaryExpr(embedding, VectorL2Distance, query) -> "embedding" <-> :query

func CF added in v0.0.6

CF creates a field comparison condition.

func CSub added in v0.0.6

func CSub(field types.Field, op types.Operator, subquery types.Subquery) types.SubqueryCondition

CSub creates a subquery condition with a field.

func CSubExists added in v0.0.6

func CSubExists(op types.Operator, subquery types.Subquery) types.SubqueryCondition

CSubExists creates an EXISTS/NOT EXISTS subquery condition.

func Cast added in v0.0.14

func Cast(field types.Field, castType types.CastType) types.FieldExpression

Example: Cast(field, CastText) -> CAST("field" AS TEXT).

func Ceil added in v0.0.6

func Ceil(field types.Field) types.FieldExpression

Ceil creates a CEIL math expression.

func Coalesce added in v0.0.6

func Coalesce(values ...types.Param) types.FieldExpression

Coalesce creates a COALESCE expression that returns the first non-null value.

func Concat added in v0.0.16

func Concat(fields ...types.Field) types.FieldExpression

Concat creates a CONCAT string expression with multiple fields. Example: Concat(field1, field2) -> CONCAT("field1", "field2")

func CountDistinct added in v0.0.6

func CountDistinct(field types.Field) types.FieldExpression

CountDistinct creates a COUNT(DISTINCT) aggregate expression.

func CountDistinctFilter added in v0.0.14

func CountDistinctFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

CountDistinctFilter creates a COUNT(DISTINCT field) aggregate with a FILTER clause.

func CountField added in v0.0.6

func CountField(field types.Field) types.FieldExpression

CountField creates a COUNT aggregate expression for a specific field.

func CountFieldFilter added in v0.0.14

func CountFieldFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

CountFieldFilter creates a COUNT(field) aggregate with a FILTER clause.

func CountStar added in v0.0.14

func CountStar() types.FieldExpression

CountStar creates a COUNT(*) aggregate expression for use in SELECT.

func CurrentDate added in v0.0.16

func CurrentDate() types.FieldExpression

CurrentDate creates a CURRENT_DATE expression returning current date. Example: CurrentDate() -> CURRENT_DATE

func CurrentTime added in v0.0.16

func CurrentTime() types.FieldExpression

CurrentTime creates a CURRENT_TIME expression returning current time. Example: CurrentTime() -> CURRENT_TIME

func CurrentTimestamp added in v0.0.16

func CurrentTimestamp() types.FieldExpression

CurrentTimestamp creates a CURRENT_TIMESTAMP expression. Example: CurrentTimestamp() -> CURRENT_TIMESTAMP

func DateTrunc added in v0.0.16

func DateTrunc(part types.DatePart, field types.Field) types.FieldExpression

DateTrunc creates a DATE_TRUNC expression to truncate to specified precision. Example: DateTrunc(PartMonth, field) -> DATE_TRUNC('month', "field")

func Extract added in v0.0.16

func Extract(part types.DatePart, field types.Field) types.FieldExpression

Extract creates an EXTRACT expression to get a part of a date/time field. Example: Extract(PartYear, field) -> EXTRACT(YEAR FROM "field")

func Floor added in v0.0.6

func Floor(field types.Field) types.FieldExpression

Floor creates a FLOOR math expression.

func HavingAvg added in v0.0.14

func HavingAvg(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

Example: HavingAvg(field, LT, param) -> HAVING AVG("field") < :param.

func HavingCount added in v0.0.14

func HavingCount(op types.Operator, value types.Param) types.AggregateCondition

Example: HavingCount(GT, param) -> HAVING COUNT(*) > :param.

func HavingCountDistinct added in v0.0.14

func HavingCountDistinct(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

HavingCountDistinct creates a HAVING COUNT(DISTINCT field) condition.

func HavingCountField added in v0.0.14

func HavingCountField(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

Example: HavingCountField(field, GT, param) -> HAVING COUNT("field") > :param.

func HavingMax added in v0.0.14

func HavingMax(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

HavingMax creates a HAVING MAX(field) condition.

func HavingMin added in v0.0.14

func HavingMin(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

HavingMin creates a HAVING MIN(field) condition.

func HavingSum added in v0.0.14

func HavingSum(field types.Field, op types.Operator, value types.Param) types.AggregateCondition

Example: HavingSum(field, GE, param) -> HAVING SUM("field") >= :param.

func LTrim added in v0.0.16

func LTrim(field types.Field) types.FieldExpression

LTrim creates an LTRIM string expression. Example: LTrim(field) -> LTRIM("field")

func Length added in v0.0.16

func Length(field types.Field) types.FieldExpression

Length creates a LENGTH string expression. Example: Length(field) -> LENGTH("field")

func Lower added in v0.0.16

func Lower(field types.Field) types.FieldExpression

Lower creates a LOWER string expression. Example: Lower(field) -> LOWER("field")

func Max added in v0.0.6

func Max(field types.Field) types.FieldExpression

Max creates a MAX aggregate expression.

func MaxFilter added in v0.0.14

func MaxFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

MaxFilter creates a MAX aggregate with a FILTER clause.

func Min added in v0.0.6

func Min(field types.Field) types.FieldExpression

Min creates a MIN aggregate expression.

func MinFilter added in v0.0.14

func MinFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

MinFilter creates a MIN aggregate with a FILTER clause.

func NotBetween added in v0.0.14

func NotBetween(field types.Field, low, high types.Param) types.BetweenCondition

Example: NotBetween(field, low, high) -> field NOT BETWEEN :low AND :high.

func Now added in v0.0.16

func Now() types.FieldExpression

Now creates a NOW() date expression returning current timestamp. Example: Now() -> NOW()

func NullIf added in v0.0.6

func NullIf(value1, value2 types.Param) types.FieldExpression

NullIf creates a NULLIF expression that returns NULL if two values are equal.

func Power added in v0.0.6

func Power(field types.Field, exponent types.Param) types.FieldExpression

Power creates a POWER math expression.

func RTrim added in v0.0.16

func RTrim(field types.Field) types.FieldExpression

RTrim creates an RTRIM string expression. Example: RTrim(field) -> RTRIM("field")

func Replace added in v0.0.16

func Replace(field types.Field, search types.Param, replacement types.Param) types.FieldExpression

Replace creates a REPLACE string expression. Example: Replace(field, search, replacement) -> REPLACE("field", :search, :replacement)

func Round added in v0.0.6

func Round(field types.Field, precision ...types.Param) types.FieldExpression

Round creates a ROUND math expression.

func Sqrt added in v0.0.6

func Sqrt(field types.Field) types.FieldExpression

Sqrt creates a SQRT math expression.

func Sub added in v0.0.6

func Sub(builder *Builder) types.Subquery

Sub creates a subquery from a builder.

func Substring added in v0.0.16

func Substring(field types.Field, start types.Param, length types.Param) types.FieldExpression

Substring creates a SUBSTRING string expression. Example: Substring(field, start, length) -> SUBSTRING("field", :start, :length)

func Sum added in v0.0.6

func Sum(field types.Field) types.FieldExpression

Sum creates a SUM aggregate expression.

func SumFilter added in v0.0.14

func SumFilter(field types.Field, filter types.ConditionItem) types.FieldExpression

Example: SumFilter(field, condition) -> SUM("field") FILTER (WHERE condition).

func Trim added in v0.0.16

func Trim(field types.Field) types.FieldExpression

Trim creates a TRIM string expression. Example: Trim(field) -> TRIM("field")

func Upper added in v0.0.16

func Upper(field types.Field) types.FieldExpression

Upper creates an UPPER string expression. Example: Upper(field) -> UPPER("field")

Types

type AST added in v0.0.8

type AST = types.AST

AST represents the abstract syntax tree for a query. This is re-exported from internal/types for use by consumers.

type ASTQL added in v0.0.6

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

ASTQL represents an instance of the query builder with a specific DBML schema.

func NewFromDBML added in v0.0.6

func NewFromDBML(project *dbml.Project) (*ASTQL, error)

NewFromDBML creates a new ASTQL instance from a DBML project.

func (*ASTQL) ASC added in v0.0.11

func (*ASTQL) ASC() types.Direction

ASC returns the ascending sort direction constant.

func (*ASTQL) AggC added in v0.0.14

func (a *ASTQL) AggC(aggFunc types.AggregateFunc, field *types.Field, op types.Operator, param types.Param) types.AggregateCondition

AggC creates a validated aggregate condition for HAVING clauses. Use nil for field to create COUNT(*).

func (*ASTQL) And added in v0.0.6

func (a *ASTQL) And(conditions ...types.ConditionItem) types.ConditionGroup

And creates an AND condition group.

func (*ASTQL) ArrayContainedBy added in v0.0.14

func (*ASTQL) ArrayContainedBy() types.Operator

ArrayContainedBy returns the array contained by operator constant (PostgreSQL <@).

func (*ASTQL) ArrayContains added in v0.0.14

func (*ASTQL) ArrayContains() types.Operator

ArrayContains returns the array contains operator constant (PostgreSQL @>).

func (*ASTQL) ArrayOverlap added in v0.0.14

func (*ASTQL) ArrayOverlap() types.Operator

ArrayOverlap returns the array overlap operator constant (PostgreSQL &&).

func (*ASTQL) C added in v0.0.6

func (a *ASTQL) C(field types.Field, op types.Operator, param types.Param) types.Condition

C creates a validated condition.

func (*ASTQL) ConditionItems added in v0.0.9

func (*ASTQL) ConditionItems() []types.ConditionItem

ConditionItems returns an empty slice of ConditionItem for programmatic query building.

func (*ASTQL) Conditions added in v0.0.8

func (*ASTQL) Conditions() []types.Condition

Conditions returns an empty slice of Condition for programmatic query building.

func (*ASTQL) DESC added in v0.0.11

func (*ASTQL) DESC() types.Direction

DESC returns the descending sort direction constant.

func (*ASTQL) EQ added in v0.0.11

func (*ASTQL) EQ() types.Operator

EQ returns the equals operator constant.

func (*ASTQL) EXISTS added in v0.0.11

func (*ASTQL) EXISTS() types.Operator

EXISTS returns the EXISTS operator constant.

func (*ASTQL) F added in v0.0.6

func (a *ASTQL) F(name string) types.Field

F creates a validated field reference.

func (*ASTQL) Fields added in v0.0.8

func (*ASTQL) Fields() []types.Field

Fields returns an empty slice of Field for programmatic query building.

func (*ASTQL) GE added in v0.0.11

func (*ASTQL) GE() types.Operator

GE returns the greater than or equal operator constant.

func (*ASTQL) GT added in v0.0.11

func (*ASTQL) GT() types.Operator

GT returns the greater than operator constant.

func (*ASTQL) GetInstance added in v0.0.6

func (a *ASTQL) GetInstance() *ASTQL

GetInstance returns the ASTQL instance (for use by provider packages).

func (*ASTQL) ILIKE added in v0.0.14

func (*ASTQL) ILIKE() types.Operator

ILIKE returns the case-insensitive LIKE operator constant (PostgreSQL).

func (*ASTQL) IN added in v0.0.11

func (*ASTQL) IN() types.Operator

IN returns the IN operator constant.

func (*ASTQL) IsNotNull added in v0.0.11

func (*ASTQL) IsNotNull() types.Operator

IsNotNull returns the IS NOT NULL operator constant.

func (*ASTQL) IsNull added in v0.0.11

func (*ASTQL) IsNull() types.Operator

IsNull returns the IS NULL operator constant.

func (*ASTQL) JSONBPath added in v1.0.4

func (a *ASTQL) JSONBPath(field types.Field, key types.Param) types.Field

JSONBPath creates a field with JSONB path access (->). The key is parameterized for safety - renders as: field->:key_param Example: JSONBPath(metadata, P("tags_key")) -> "metadata"->:tags_key

func (*ASTQL) JSONBText added in v1.0.4

func (a *ASTQL) JSONBText(field types.Field, key types.Param) types.Field

JSONBText creates a field with JSONB text extraction (->>). The key is parameterized for safety - renders as: field->>:key_param Example: JSONBText(metadata, P("status_key")) -> "metadata"->>:status_key

func (*ASTQL) LE added in v0.0.11

func (*ASTQL) LE() types.Operator

LE returns the less than or equal operator constant.

func (*ASTQL) LIKE added in v0.0.11

func (*ASTQL) LIKE() types.Operator

LIKE returns the LIKE operator constant.

func (*ASTQL) LT added in v0.0.11

func (*ASTQL) LT() types.Operator

LT returns the less than operator constant.

func (*ASTQL) NE added in v0.0.11

func (*ASTQL) NE() types.Operator

NE returns the not equals operator constant.

func (*ASTQL) NotExists added in v0.0.11

func (*ASTQL) NotExists() types.Operator

NotExists returns the NOT EXISTS operator constant.

func (*ASTQL) NotILike added in v0.0.14

func (*ASTQL) NotILike() types.Operator

NotILike returns the NOT ILIKE operator constant (PostgreSQL).

func (*ASTQL) NotIn added in v0.0.11

func (*ASTQL) NotIn() types.Operator

NotIn returns the NOT IN operator constant.

func (*ASTQL) NotLike added in v0.0.11

func (*ASTQL) NotLike() types.Operator

NotLike returns the NOT LIKE operator constant.

func (*ASTQL) NotNull added in v0.0.6

func (a *ASTQL) NotNull(field types.Field) types.Condition

NotNull creates a NOT NULL condition.

func (*ASTQL) NotRegexIMatch added in v0.0.14

func (*ASTQL) NotRegexIMatch() types.Operator

NotRegexIMatch returns the case-insensitive regex non-match operator constant (PostgreSQL !~*).

func (*ASTQL) NotRegexMatch added in v0.0.14

func (*ASTQL) NotRegexMatch() types.Operator

NotRegexMatch returns the regex non-match operator constant (PostgreSQL !~).

func (*ASTQL) Null added in v0.0.6

func (a *ASTQL) Null(field types.Field) types.Condition

Null creates a NULL condition.

func (*ASTQL) OpCount added in v0.0.11

func (*ASTQL) OpCount() types.Operation

OpCount returns the Count operation constant.

func (*ASTQL) OpDelete added in v0.0.11

func (*ASTQL) OpDelete() types.Operation

OpDelete returns the Delete operation constant.

func (*ASTQL) OpInsert added in v0.0.11

func (*ASTQL) OpInsert() types.Operation

OpInsert returns the Insert operation constant.

func (*ASTQL) OpSelect added in v0.0.11

func (*ASTQL) OpSelect() types.Operation

OpSelect returns the Select operation constant.

func (*ASTQL) OpUpdate added in v0.0.11

func (*ASTQL) OpUpdate() types.Operation

OpUpdate returns the Update operation constant.

func (*ASTQL) Or added in v0.0.6

func (a *ASTQL) Or(conditions ...types.ConditionItem) types.ConditionGroup

Or creates an OR condition group.

func (*ASTQL) P added in v0.0.6

func (a *ASTQL) P(name string) types.Param

P creates a validated parameter reference.

func (*ASTQL) Params added in v0.0.19

func (*ASTQL) Params() []types.Param

Params returns an empty slice of Param for programmatic query building.

func (*ASTQL) RegexIMatch added in v0.0.14

func (*ASTQL) RegexIMatch() types.Operator

RegexIMatch returns the case-insensitive regex match operator constant (PostgreSQL ~*).

func (*ASTQL) RegexMatch added in v0.0.14

func (*ASTQL) RegexMatch() types.Operator

RegexMatch returns the regex match operator constant (PostgreSQL ~).

func (*ASTQL) T added in v0.0.6

func (a *ASTQL) T(name string, alias ...string) types.Table

T creates a validated table reference.

func (*ASTQL) TryAggC added in v0.0.14

func (a *ASTQL) TryAggC(aggFunc types.AggregateFunc, field *types.Field, op types.Operator, param types.Param) (types.AggregateCondition, error)

TryAggC creates a validated aggregate condition for HAVING clauses. Use nil for field to create COUNT(*).

func (*ASTQL) TryAnd added in v0.0.6

func (*ASTQL) TryAnd(conditions ...types.ConditionItem) (types.ConditionGroup, error)

TryAnd creates an AND condition group, returning an error if invalid.

func (*ASTQL) TryC added in v0.0.6

func (a *ASTQL) TryC(field types.Field, op types.Operator, param types.Param) (types.Condition, error)

TryC creates a validated condition, returning an error if invalid.

func (*ASTQL) TryF added in v0.0.6

func (a *ASTQL) TryF(name string) (types.Field, error)

TryF creates a validated field reference, returning an error if invalid.

func (*ASTQL) TryNotNull added in v0.0.6

func (a *ASTQL) TryNotNull(field types.Field) (types.Condition, error)

TryNotNull creates a NOT NULL condition, returning an error if invalid.

func (*ASTQL) TryNull added in v0.0.6

func (a *ASTQL) TryNull(field types.Field) (types.Condition, error)

TryNull creates a NULL condition, returning an error if invalid.

func (*ASTQL) TryOr added in v0.0.6

func (*ASTQL) TryOr(conditions ...types.ConditionItem) (types.ConditionGroup, error)

TryOr creates an OR condition group, returning an error if invalid.

func (*ASTQL) TryP added in v0.0.6

func (*ASTQL) TryP(name string) (types.Param, error)

TryP creates a validated parameter reference, returning an error if invalid.

func (*ASTQL) TryT added in v0.0.6

func (a *ASTQL) TryT(name string, alias ...string) (types.Table, error)

TryT creates a validated table reference, returning an error if invalid.

func (*ASTQL) TryWithTable added in v0.0.6

func (a *ASTQL) TryWithTable(field types.Field, tableOrAlias string) (types.Field, error)

TryWithTable creates a new Field with a table/alias prefix, returning an error if invalid.

func (*ASTQL) ValueMap added in v0.0.8

func (*ASTQL) ValueMap() map[types.Field]types.Param

ValueMap returns an empty map for programmatic INSERT value building.

func (*ASTQL) VectorCosineDistance added in v0.0.11

func (*ASTQL) VectorCosineDistance() types.Operator

VectorCosineDistance returns the vector cosine distance operator constant (pgvector <=>).

func (*ASTQL) VectorInnerProduct added in v0.0.11

func (*ASTQL) VectorInnerProduct() types.Operator

VectorInnerProduct returns the vector negative inner product operator constant (pgvector <#>).

func (*ASTQL) VectorL1Distance added in v0.0.11

func (*ASTQL) VectorL1Distance() types.Operator

VectorL1Distance returns the vector L1/Manhattan distance operator constant (pgvector <+>).

func (*ASTQL) VectorL2Distance added in v0.0.11

func (*ASTQL) VectorL2Distance() types.Operator

VectorL2Distance returns the vector L2/Euclidean distance operator constant (pgvector <->).

func (*ASTQL) WithTable added in v0.0.6

func (a *ASTQL) WithTable(field types.Field, tableOrAlias string) types.Field

WithTable creates a new Field with a table/alias prefix, validated against the schema.

type AggregateCondition added in v0.0.14

type AggregateCondition = types.AggregateCondition

AggregateCondition represents a HAVING condition on an aggregate function. Use with Builder.HavingAgg() for conditions like COUNT(*) > 10.

type AggregateFunc added in v0.0.14

type AggregateFunc = types.AggregateFunc

AggregateFunc represents SQL aggregate functions.

type BetweenCondition added in v0.0.14

type BetweenCondition = types.BetweenCondition

BetweenCondition represents a BETWEEN condition with two bounds.

type BinaryExpression added in v1.0.4

type BinaryExpression = types.BinaryExpression

BinaryExpression represents a binary operation between a field and a parameter. Used for expressions like vector distance calculations: field <-> :param

type Builder

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

Builder provides a fluent API for constructing queries.

func Count

func Count(t types.Table) *Builder

Count creates a new COUNT query builder.

func Delete

func Delete(t types.Table) *Builder

Delete creates a new DELETE query builder.

func Insert

func Insert(t types.Table) *Builder

Insert creates a new INSERT query builder.

func Select

func Select(t types.Table) *Builder

Select creates a new SELECT query builder.

func Update

func Update(t types.Table) *Builder

Update creates a new UPDATE query builder.

func (*Builder) Build

func (b *Builder) Build() (*types.AST, error)

Build returns the constructed AST or an error.

func (*Builder) CrossJoin added in v0.0.6

func (b *Builder) CrossJoin(table types.Table) *Builder

CrossJoin adds a CROSS JOIN (no ON clause needed).

func (*Builder) Distinct added in v0.0.6

func (b *Builder) Distinct() *Builder

Distinct sets the DISTINCT flag for SELECT queries.

func (*Builder) DistinctOn added in v0.0.14

func (b *Builder) DistinctOn(fields ...types.Field) *Builder

DistinctOn sets DISTINCT ON fields for SELECT queries (PostgreSQL). The query will return only the first row for each unique combination of the specified fields.

func (*Builder) Except added in v0.0.14

func (b *Builder) Except(other *Builder) *CompoundBuilder

Except creates an EXCEPT between two queries.

func (*Builder) ExceptAll added in v0.0.14

func (b *Builder) ExceptAll(other *Builder) *CompoundBuilder

ExceptAll creates an EXCEPT ALL between two queries.

func (*Builder) Fields

func (b *Builder) Fields(fields ...types.Field) *Builder

Fields sets the fields to select.

func (*Builder) ForKeyShare added in v0.0.14

func (b *Builder) ForKeyShare() *Builder

ForKeyShare adds FOR KEY SHARE row locking.

func (*Builder) ForNoKeyUpdate added in v0.0.14

func (b *Builder) ForNoKeyUpdate() *Builder

ForNoKeyUpdate adds FOR NO KEY UPDATE row locking.

func (*Builder) ForShare added in v0.0.14

func (b *Builder) ForShare() *Builder

ForShare adds FOR SHARE row locking.

func (*Builder) ForUpdate added in v0.0.14

func (b *Builder) ForUpdate() *Builder

ForUpdate adds FOR UPDATE row locking.

func (*Builder) FullOuterJoin added in v0.0.14

func (b *Builder) FullOuterJoin(table types.Table, on types.ConditionItem) *Builder

FullOuterJoin adds a FULL OUTER JOIN.

func (*Builder) GetAST

func (b *Builder) GetAST() *types.AST

GetAST returns the internal AST.

func (*Builder) GetError

func (b *Builder) GetError() error

GetError returns the internal error (for use by provider packages).

func (*Builder) GroupBy added in v0.0.6

func (b *Builder) GroupBy(fields ...types.Field) *Builder

GroupBy adds GROUP BY fields.

func (*Builder) Having added in v0.0.6

func (b *Builder) Having(conditions ...types.Condition) *Builder

Having adds HAVING conditions (simple field-based conditions). For aggregate conditions like COUNT(*) > 10, use HavingAgg instead.

func (*Builder) HavingAgg added in v0.0.14

func (b *Builder) HavingAgg(conditions ...types.AggregateCondition) *Builder

HavingAgg adds aggregate HAVING conditions like COUNT(*) > :min_count. Use this for conditions on aggregate functions (COUNT, SUM, AVG, MIN, MAX).

func (*Builder) InnerJoin added in v0.0.6

func (b *Builder) InnerJoin(table types.Table, on types.ConditionItem) *Builder

InnerJoin adds an INNER JOIN.

func (*Builder) Intersect added in v0.0.14

func (b *Builder) Intersect(other *Builder) *CompoundBuilder

Intersect creates an INTERSECT between two queries.

func (*Builder) IntersectAll added in v0.0.14

func (b *Builder) IntersectAll(other *Builder) *CompoundBuilder

IntersectAll creates an INTERSECT ALL between two queries.

func (*Builder) Join added in v0.0.6

func (b *Builder) Join(table types.Table, on types.ConditionItem) *Builder

Join adds an INNER JOIN.

func (*Builder) LeftJoin added in v0.0.6

func (b *Builder) LeftJoin(table types.Table, on types.ConditionItem) *Builder

LeftJoin adds a LEFT JOIN.

func (*Builder) Limit

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

Limit sets the limit to a static integer value.

func (*Builder) LimitParam added in v0.0.16

func (b *Builder) LimitParam(param types.Param) *Builder

LimitParam sets the limit to a parameterized value.

func (*Builder) MustBuild

func (b *Builder) MustBuild() *types.AST

MustBuild returns the AST or panics on error.

func (*Builder) MustRender added in v0.0.6

func (b *Builder) MustRender(renderer Renderer) *QueryResult

MustRender builds and renders the AST with the provided renderer, or panics on error.

func (*Builder) Offset

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

Offset sets the offset to a static integer value.

func (*Builder) OffsetParam added in v0.0.16

func (b *Builder) OffsetParam(param types.Param) *Builder

OffsetParam sets the offset to a parameterized value.

func (*Builder) OnConflict added in v0.0.6

func (b *Builder) OnConflict(columns ...types.Field) *ConflictBuilder

OnConflict adds ON CONFLICT clause for INSERT.

func (*Builder) OrderBy

func (b *Builder) OrderBy(f types.Field, direction types.Direction) *Builder

OrderBy adds ordering.

func (*Builder) OrderByExpr added in v0.0.12

func (b *Builder) OrderByExpr(f types.Field, op types.Operator, p types.Param, direction types.Direction) *Builder

OrderByExpr is useful for vector distance ordering: ORDER BY embedding <-> :query_vector ASC.

func (*Builder) OrderByNulls added in v0.0.14

func (b *Builder) OrderByNulls(f types.Field, direction types.Direction, nulls types.NullsOrdering) *Builder

OrderByNulls adds ordering with NULLS FIRST/LAST.

func (*Builder) Render added in v0.0.6

func (b *Builder) Render(renderer Renderer) (*QueryResult, error)

Render builds the AST and renders it using the provided renderer.

func (*Builder) Returning added in v0.0.6

func (b *Builder) Returning(fields ...types.Field) *Builder

Returning adds RETURNING fields for INSERT/UPDATE/DELETE.

func (*Builder) RightJoin added in v0.0.6

func (b *Builder) RightJoin(table types.Table, on types.ConditionItem) *Builder

RightJoin adds a RIGHT JOIN.

func (*Builder) SelectBinaryExpr added in v1.0.5

func (b *Builder) SelectBinaryExpr(f types.Field, op types.Operator, p types.Param, alias string) *Builder

SelectBinaryExpr adds a binary expression (field <op> param) AS alias to SELECT. Useful for vector distance calculations with pgvector.

Example:

builder.SelectBinaryExpr(f, VectorCosineDistance, p, "score")
// Renders: "field" <=> :param AS "score"

func (*Builder) SelectExpr added in v0.0.6

func (b *Builder) SelectExpr(expr types.FieldExpression) *Builder

SelectExpr adds a field expression (aggregate, case, etc) to SELECT.

func (*Builder) Set

func (b *Builder) Set(f types.Field, p types.Param) *Builder

Set adds a field update for UPDATE queries.

func (*Builder) SetError

func (b *Builder) SetError(err error)

SetError sets the internal error (for use by provider packages).

func (*Builder) SetExpr added in v1.0.6

func (b *Builder) SetExpr(f types.Field, expr types.FieldExpression) *Builder

SetExpr adds a field update with an expression value for UPDATE queries. Use this for computed assignments like `items_completed = items_completed + :increment`.

func (*Builder) Union added in v0.0.14

func (b *Builder) Union(other *Builder) *CompoundBuilder

Union creates a UNION between two queries.

func (*Builder) UnionAll added in v0.0.14

func (b *Builder) UnionAll(other *Builder) *CompoundBuilder

UnionAll creates a UNION ALL between two queries.

func (*Builder) Values

func (b *Builder) Values(valueMap map[types.Field]types.Param) *Builder

Values adds a row of field-value pairs for INSERT queries. Call Values() multiple times to insert multiple rows. Use instance.ValueMap() to create the map programmatically.

func (*Builder) Where

func (b *Builder) Where(condition types.ConditionItem) *Builder

Where sets or adds conditions.

func (*Builder) WhereField

func (b *Builder) WhereField(f types.Field, op types.Operator, p types.Param) *Builder

WhereField is a convenience method for simple field conditions.

type CaseBuilder added in v0.0.6

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

CaseBuilder provides fluent API for building CASE expressions.

func Case added in v0.0.6

func Case() *CaseBuilder

Case creates a new CASE expression builder.

func (*CaseBuilder) As added in v0.0.6

func (cb *CaseBuilder) As(alias string) *CaseBuilder

As adds an alias to the CASE expression.

func (*CaseBuilder) Build added in v0.0.6

func (cb *CaseBuilder) Build() types.FieldExpression

Build returns the CaseExpression wrapped in a FieldExpression.

func (*CaseBuilder) Else added in v0.0.6

func (cb *CaseBuilder) Else(result types.Param) *CaseBuilder

Else sets the ELSE clause.

func (*CaseBuilder) When added in v0.0.6

func (cb *CaseBuilder) When(condition types.ConditionItem, result types.Param) *CaseBuilder

When adds a WHEN...THEN clause.

type CastType added in v0.0.14

type CastType = types.CastType

CastType represents allowed PostgreSQL data types for casting.

type CompoundBuilder added in v0.0.14

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

CompoundBuilder handles building compound queries with set operations.

func Except added in v0.0.14

func Except(first, second *Builder) *CompoundBuilder

Except creates an EXCEPT between two queries (standalone function).

func ExceptAll added in v0.0.14

func ExceptAll(first, second *Builder) *CompoundBuilder

ExceptAll creates an EXCEPT ALL between two queries (standalone function).

func Intersect added in v0.0.14

func Intersect(first, second *Builder) *CompoundBuilder

Intersect creates an INTERSECT between two queries (standalone function).

func IntersectAll added in v0.0.14

func IntersectAll(first, second *Builder) *CompoundBuilder

IntersectAll creates an INTERSECT ALL between two queries (standalone function).

func Union added in v0.0.14

func Union(first, second *Builder) *CompoundBuilder

Union creates a UNION between two queries (standalone function).

func UnionAll added in v0.0.14

func UnionAll(first, second *Builder) *CompoundBuilder

UnionAll creates a UNION ALL between two queries (standalone function).

func (*CompoundBuilder) Build added in v0.0.14

func (cb *CompoundBuilder) Build() (*types.CompoundQuery, error)

Build returns the CompoundQuery or an error.

func (*CompoundBuilder) Except added in v0.0.14

func (cb *CompoundBuilder) Except(other *Builder) *CompoundBuilder

Except adds an EXCEPT to the compound query.

func (*CompoundBuilder) ExceptAll added in v0.0.14

func (cb *CompoundBuilder) ExceptAll(other *Builder) *CompoundBuilder

ExceptAll adds an EXCEPT ALL to the compound query.

func (*CompoundBuilder) Intersect added in v0.0.14

func (cb *CompoundBuilder) Intersect(other *Builder) *CompoundBuilder

Intersect adds an INTERSECT to the compound query.

func (*CompoundBuilder) IntersectAll added in v0.0.14

func (cb *CompoundBuilder) IntersectAll(other *Builder) *CompoundBuilder

IntersectAll adds an INTERSECT ALL to the compound query.

func (*CompoundBuilder) Limit added in v0.0.14

func (cb *CompoundBuilder) Limit(limit int) *CompoundBuilder

Limit sets the limit for the compound query to a static integer value.

func (*CompoundBuilder) LimitParam added in v0.0.16

func (cb *CompoundBuilder) LimitParam(param types.Param) *CompoundBuilder

LimitParam sets the limit for the compound query to a parameterized value.

func (*CompoundBuilder) MustBuild added in v0.0.14

func (cb *CompoundBuilder) MustBuild() *types.CompoundQuery

MustBuild returns the CompoundQuery or panics on error.

func (*CompoundBuilder) MustRender added in v0.0.14

func (cb *CompoundBuilder) MustRender(renderer Renderer) *QueryResult

MustRender builds and renders the compound query with the provided renderer, or panics on error.

func (*CompoundBuilder) Offset added in v0.0.14

func (cb *CompoundBuilder) Offset(offset int) *CompoundBuilder

Offset sets the offset for the compound query to a static integer value.

func (*CompoundBuilder) OffsetParam added in v0.0.16

func (cb *CompoundBuilder) OffsetParam(param types.Param) *CompoundBuilder

OffsetParam sets the offset for the compound query to a parameterized value.

func (*CompoundBuilder) OrderBy added in v0.0.14

func (cb *CompoundBuilder) OrderBy(f types.Field, direction types.Direction) *CompoundBuilder

OrderBy adds final ordering to the compound query.

func (*CompoundBuilder) OrderByNulls added in v1.0.4

func (cb *CompoundBuilder) OrderByNulls(f types.Field, direction types.Direction, nulls types.NullsOrdering) *CompoundBuilder

OrderByNulls adds final ordering with NULLS FIRST/LAST to the compound query.

func (*CompoundBuilder) Render added in v0.0.14

func (cb *CompoundBuilder) Render(renderer Renderer) (*QueryResult, error)

Render builds and renders the compound query using the provided renderer.

func (*CompoundBuilder) Union added in v0.0.14

func (cb *CompoundBuilder) Union(other *Builder) *CompoundBuilder

Union adds a UNION to the compound query.

func (*CompoundBuilder) UnionAll added in v0.0.14

func (cb *CompoundBuilder) UnionAll(other *Builder) *CompoundBuilder

UnionAll adds a UNION ALL to the compound query.

type CompoundQuery added in v0.0.14

type CompoundQuery = types.CompoundQuery

CompoundQuery represents a query with set operations.

type ConditionItem added in v0.0.10

type ConditionItem = types.ConditionItem

ConditionItem represents either a single condition or a group of conditions.

type ConflictBuilder added in v0.0.6

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

ConflictBuilder handles ON CONFLICT actions.

func (*ConflictBuilder) DoNothing added in v0.0.6

func (cb *ConflictBuilder) DoNothing() *Builder

DoNothing sets the conflict action to DO NOTHING.

func (*ConflictBuilder) DoUpdate added in v0.0.6

func (cb *ConflictBuilder) DoUpdate() *UpdateBuilder

DoUpdate sets the conflict action to DO UPDATE.

type Direction added in v0.0.8

type Direction = types.Direction

Direction represents sort direction.

type FrameBound added in v0.0.14

type FrameBound = types.FrameBound

FrameBound represents window frame boundaries.

type NullsOrdering added in v0.0.14

type NullsOrdering = types.NullsOrdering

NullsOrdering represents NULL ordering in ORDER BY.

type Operation added in v0.0.8

type Operation = types.Operation

Operation represents the type of query operation.

type Operator added in v0.0.8

type Operator = types.Operator

Operator represents SQL comparison operators.

type QueryResult

type QueryResult = types.QueryResult

QueryResult contains the rendered SQL and required parameters.

type Renderer added in v0.0.16

type Renderer interface {
	// Render converts an AST to a QueryResult with dialect-specific SQL.
	Render(ast *types.AST) (*types.QueryResult, error)

	// RenderCompound converts a CompoundQuery (UNION, INTERSECT, EXCEPT) to SQL.
	RenderCompound(query *types.CompoundQuery) (*types.QueryResult, error)

	// Capabilities returns the SQL features supported by this dialect.
	Capabilities() render.Capabilities
}

Renderer defines the interface for SQL dialect-specific rendering. Implementations convert an AST to dialect-specific SQL with named parameters.

type SetOperand added in v0.0.14

type SetOperand = types.SetOperand

SetOperand represents one operand in a set operation.

type SetOperation added in v0.0.14

type SetOperation = types.SetOperation

SetOperation represents SQL set operations (UNION, INTERSECT, EXCEPT).

type UpdateBuilder added in v0.0.6

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

UpdateBuilder handles DO UPDATE SET clause construction.

func (*UpdateBuilder) Build added in v0.0.6

func (ub *UpdateBuilder) Build() *Builder

Build finalizes the update and returns the builder.

func (*UpdateBuilder) Set added in v0.0.6

func (ub *UpdateBuilder) Set(field types.Field, param types.Param) *UpdateBuilder

Set adds a field to update on conflict.

type WindowBuilder added in v0.0.14

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

WindowBuilder provides a fluent API for building window function expressions.

func AvgOver added in v0.0.14

func AvgOver(field types.Field) *WindowBuilder

AvgOver creates an AVG() OVER window function.

func CountOver added in v0.0.14

func CountOver(field ...types.Field) *WindowBuilder

CountOver creates a COUNT(field) OVER window function.

func DenseRank added in v0.0.14

func DenseRank() *WindowBuilder

DenseRank creates a DENSE_RANK() window function.

func FirstValue added in v0.0.14

func FirstValue(field types.Field) *WindowBuilder

FirstValue creates a FIRST_VALUE(field) window function.

func Lag added in v0.0.14

func Lag(field types.Field, offset types.Param, defaultVal ...types.Param) *WindowBuilder

Lag creates a LAG(field, offset, default) window function.

func LastValue added in v0.0.14

func LastValue(field types.Field) *WindowBuilder

LastValue creates a LAST_VALUE(field) window function.

func Lead added in v0.0.14

func Lead(field types.Field, offset types.Param, defaultVal ...types.Param) *WindowBuilder

Lead creates a LEAD(field, offset, default) window function.

func MaxOver added in v0.0.14

func MaxOver(field types.Field) *WindowBuilder

MaxOver creates a MAX() OVER window function.

func MinOver added in v0.0.14

func MinOver(field types.Field) *WindowBuilder

MinOver creates a MIN() OVER window function.

func Ntile added in v0.0.14

func Ntile(n types.Param) *WindowBuilder

Ntile creates an NTILE(n) window function.

func Rank added in v0.0.14

func Rank() *WindowBuilder

Rank creates a RANK() window function.

func RowNumber added in v0.0.14

func RowNumber() *WindowBuilder

RowNumber creates a ROW_NUMBER() window function.

func SumOver added in v0.0.14

func SumOver(field types.Field) *WindowBuilder

SumOver creates a SUM() OVER window function.

func (*WindowBuilder) As added in v0.0.14

func (wb *WindowBuilder) As(alias string) types.FieldExpression

As adds an alias to the window function and returns a FieldExpression.

func (*WindowBuilder) Build added in v0.0.14

func (wb *WindowBuilder) Build() types.FieldExpression

Build returns the FieldExpression without an alias.

func (*WindowBuilder) Frame added in v0.0.14

func (wb *WindowBuilder) Frame(start, end types.FrameBound) *WindowBuilder

Frame sets the frame clause with ROWS BETWEEN (convenience method).

func (*WindowBuilder) OrderBy added in v0.0.14

func (wb *WindowBuilder) OrderBy(field types.Field, direction types.Direction) *WindowBuilder

OrderBy adds ORDER BY to the window specification (convenience method).

func (*WindowBuilder) Over added in v0.0.14

func (wb *WindowBuilder) Over(spec types.WindowSpec) *WindowBuilder

Over sets the window specification for a window function.

func (*WindowBuilder) OverBuilder added in v0.0.14

func (wb *WindowBuilder) OverBuilder(builder *WindowSpecBuilder) *WindowBuilder

OverBuilder sets the window specification from a builder.

func (*WindowBuilder) PartitionBy added in v0.0.14

func (wb *WindowBuilder) PartitionBy(fields ...types.Field) *WindowBuilder

PartitionBy adds PARTITION BY fields (convenience method).

type WindowFunc added in v0.0.14

type WindowFunc = types.WindowFunc

WindowFunc represents window function types.

type WindowSpec added in v0.0.14

type WindowSpec = types.WindowSpec

WindowSpec represents a window specification.

type WindowSpecBuilder added in v0.0.14

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

WindowSpecBuilder provides a fluent API for building window specifications.

func Window added in v0.0.14

func Window() *WindowSpecBuilder

Window creates a new WindowSpec for use with window functions.

func (*WindowSpecBuilder) Build added in v0.0.14

func (wsb *WindowSpecBuilder) Build() types.WindowSpec

Build returns the WindowSpec.

func (*WindowSpecBuilder) OrderBy added in v0.0.14

func (wsb *WindowSpecBuilder) OrderBy(field types.Field, direction types.Direction) *WindowSpecBuilder

OrderBy adds ORDER BY to the window specification.

func (*WindowSpecBuilder) OrderByNulls added in v0.0.14

func (wsb *WindowSpecBuilder) OrderByNulls(field types.Field, direction types.Direction, nulls types.NullsOrdering) *WindowSpecBuilder

OrderByNulls adds ORDER BY with NULLS ordering to the window specification.

func (*WindowSpecBuilder) PartitionBy added in v0.0.14

func (wsb *WindowSpecBuilder) PartitionBy(fields ...types.Field) *WindowSpecBuilder

PartitionBy adds PARTITION BY fields to the window specification.

func (*WindowSpecBuilder) Rows added in v0.0.14

func (wsb *WindowSpecBuilder) Rows(start, end types.FrameBound) *WindowSpecBuilder

Rows sets the frame clause with ROWS BETWEEN.

Directories

Path Synopsis
internal
Package mariadb provides the MariaDB dialect renderer for astql.
Package mariadb provides the MariaDB dialect renderer for astql.
Package mssql provides the SQL Server dialect renderer for astql.
Package mssql provides the SQL Server dialect renderer for astql.
Package postgres provides the PostgreSQL dialect renderer for astql.
Package postgres provides the PostgreSQL dialect renderer for astql.
Package sqlite provides the SQLite dialect renderer for astql.
Package sqlite provides the SQLite dialect renderer for astql.
Package testing provides test utilities for astql.
Package testing provides test utilities for astql.

Jump to

Keyboard shortcuts

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