dialect

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package dialect describes the SQL language differences between the databases Momo supports. A Dialect says what the SQL *language* can express; what a particular connection driver can do (COPY, batching, extension loading) is a separate, driver-level capability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct {
	Name Name

	// Flavor is set on MySQL dialects only.
	Flavor Flavor

	// MaxParams is the largest number of bind parameters a single statement
	// may carry. PostgreSQL's wire protocol limit is 65535; SQLite's
	// default SQLITE_MAX_VARIABLE_NUMBER is 32766 since 3.32.0.
	MaxParams int

	// MaxInList caps the values in one typed IN or NOT IN list. Zero means no
	// cap. momo.WithMaxInList sets it on the per-DB copy of the dialect.
	MaxInList int

	Returning        bool // INSERT/UPDATE/DELETE ... RETURNING (SQLite >= 3.35)
	InsertReturning  bool // INSERT ... RETURNING only (MariaDB >= 10.5); Returning stays false there
	OnConflict       bool // INSERT ... ON CONFLICT
	OnDuplicateKey   bool // INSERT ... ON DUPLICATE KEY UPDATE
	Locking          bool // SELECT ... FOR UPDATE / FOR SHARE / SKIP LOCKED / NOWAIT
	NullsOrdering    bool // ORDER BY ... NULLS FIRST|LAST (SQLite >= 3.30)
	DefaultInUpdate  bool // UPDATE ... SET col = DEFAULT
	DefaultInValues  bool // INSERT ... VALUES (DEFAULT)
	RecursiveCTE     bool
	RowValues        bool // (a, b) IN ((?, ?), ...) and (a, b) > (?, ?)
	Savepoints       bool
	IsolationLevels  bool // BEGIN with an isolation level
	TransactionalDDL bool // DDL can be rolled back
	ILike            bool
	Merge            bool // MERGE statement
	WindowFunctions  bool

	// Vector describes vector storage, distance metrics and ANN indexes.
	Vector VectorCaps
}

Dialect is immutable after construction and safe for concurrent use.

func For

func For(n Name) *Dialect

For returns the built-in dialect description for name.

func MySQLFlavor

func MySQLFlavor(f Flavor) *Dialect

MySQLFlavor returns the MySQL-family dialect for the given flavor, or nil for an unknown flavor. Every call returns a fresh value.

MySQL Community has VECTOR storage from 9.0 but no distance function, so it lists no metrics and no index. MariaDB 11.8 has VEC_DISTANCE_EUCLIDEAN and VEC_DISTANCE_COSINE and VECTOR INDEX, and supports INSERT ... RETURNING but not UPDATE or DELETE ... RETURNING. A server-version gate in migrate/mysql rejects VECTOR on MySQL 8.4.

func (*Dialect) AppendIdent

func (d *Dialect) AppendIdent(b []byte, ident string) []byte

AppendIdent appends a quoted identifier. MySQL uses backticks; the other dialects use the SQL standard double-quote form. Embedded quote characters are doubled. Dotted names are NOT split: callers quote each part separately.

func (*Dialect) AppendPlaceholder

func (d *Dialect) AppendPlaceholder(b []byte, n int) []byte

AppendPlaceholder appends the n-th (1-based) bind placeholder.

func (*Dialect) QuoteIdent

func (d *Dialect) QuoteIdent(ident string) string

QuoteIdent returns a quoted identifier.

type Flavor

type Flavor string

Flavor distinguishes servers that share the MySQL dialect. It is set on MySQL dialects only.

const (
	// FlavorMySQL is Oracle MySQL.
	FlavorMySQL Flavor = "mysql"
	// FlavorMariaDB is MariaDB.
	FlavorMariaDB Flavor = "mariadb"
)

type Metric

type Metric string

Metric names a vector distance metric.

const (
	MetricL2           Metric = "l2"      // <-> on PostgreSQL; vec_distance_l2 on SQLite
	MetricInnerProduct Metric = "ip"      // <#> (negative inner product) on PostgreSQL only
	MetricCosine       Metric = "cosine"  // <=> on PostgreSQL; vec_distance_cosine on SQLite
	MetricL1           Metric = "l1"      // <+> on PostgreSQL; vec_distance_l1 on SQLite
	MetricHamming      Metric = "hamming" // <~> on PostgreSQL; vec_distance_hamming on SQLite (bit vectors)
	MetricJaccard      Metric = "jaccard" // <%> on PostgreSQL only
)

type Name

type Name string

Name identifies a dialect.

const (
	// Postgres names the PostgreSQL dialect.
	Postgres Name = "postgres"
	// SQLite names the SQLite dialect.
	SQLite Name = "sqlite"
	// MySQL names the MySQL and MariaDB dialect.
	MySQL Name = "mysql"
)

type VectorCaps

type VectorCaps struct {
	Storage bool     // vector column types can be declared
	Metrics []Metric // distance metrics this dialect renders
	Indexes []string // ANN index methods available: "hnsw", "ivfflat", "vector"
}

VectorCaps describes a dialect's vector support.

Jump to

Keyboard shortcuts

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