dialect

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package dialect holds the SQL differences between databases behind one interface: identifier quoting, placeholders, LIKE and date handling, locks, index hints and a few join/union rules. Everything the databases share lives in the compiler of the root package, so supporting a new database is a new Grammar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Grammar

type Grammar interface {
	// Quote wraps a single identifier segment, escaping embedded quote chars.
	Quote(segment string) string
	// QuoteChar is the identifier quote byte Quote wraps with, so callers can write a
	// quoted identifier straight into a buffer without allocating.
	QuoteChar() byte
	// Placeholder returns the bind marker for the n-th (1-based) argument.
	Placeholder(n int) string
	// UnboundedLimit returns the limit literal required when OFFSET is used
	// without LIMIT, or "" when the dialect accepts a bare OFFSET.
	UnboundedLimit() string
	// LikeOp returns the LIKE operator for the case-sensitivity / negation combo.
	LikeOp(caseSensitive, not bool) string
	// LikeValue adapts a LIKE pattern for the chosen operator.
	LikeValue(pattern string, caseSensitive bool) string
	// LikeCast returns a suffix appended to the wrapped column for LIKE operators.
	LikeCast(op string) string
	// NullSafeOp returns the NULL-safe equality operator.
	NullSafeOp() string
	// DatePart extracts part ("date","time","day","month","year") from a wrapped column.
	DatePart(part, col string) string
	// DateValueWrap wraps the right-hand side of a date comparison.
	DateValueWrap() (pre, post string)
	SupportsStraightJoin() bool
	SupportsLateralJoin() bool
	// UnionOpen opens a wrapped union member: "(" or "SELECT * FROM (".
	UnionOpen() string
	// LockSQL returns the locking clause, or "" when none applies.
	LockSQL(kind LockKind, raw string) string
	// IndexHint renders an index hint after the FROM table, or "" when unsupported.
	IndexHint(kind, index string) (string, error)
	// Random returns the random-order expression; seed may be nil.
	Random(seed *int) string
}

Grammar holds the per-dialect differences. Everything shared lives in the compiler.

func MariaDB

func MariaDB() Grammar

MariaDB returns the MariaDB grammar. It is MySQL's with one difference at this level: MariaDB has no LATERAL joins. The other difference, json_query instead of CAST AS JSON for JSON container values, is compiled in the root package.

func MySQL

func MySQL() Grammar

MySQL returns the MySQL grammar.

func Postgres

func Postgres() Grammar

Postgres returns the PostgreSQL grammar.

func SQLite

func SQLite() Grammar

SQLite returns the SQLite grammar.

type LockKind

type LockKind int

LockKind selects a row-locking clause.

const (
	LockNone LockKind = iota
	LockUpdate
	LockShared
	LockRaw
)

The row-locking clauses a Grammar can render.

Jump to

Keyboard shortcuts

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