dialect

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package dialect is the SQL dialect kind parse compiles for: the placeholder and identifier rules of PostgreSQL and SQLite. The filter and patch dialects embed it and add their SQL.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownDSN = errors.New("parse: unknown DSN scheme")

ErrUnknownDSN is returned by FromDSN for a DSN whose scheme names no supported database.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	// Name is "postgres" or "sqlite".
	Name() string
	// Placeholder is the nth parameter's placeholder (1-based): "$1" on
	// PostgreSQL, "?1" on SQLite.
	Placeholder(n int) string
	// QuoteIdent quotes an identifier with double quotes, doubling any
	// quote inside it.
	QuoteIdent(name string) string
}

Dialect is the dialect-specific part of a statement: its name, its placeholders and identifier quoting.

func FromDSN

func FromDSN(dsn string) (Dialect, error)

FromDSN is the dialect of a connection string.

type Postgres

type Postgres struct{}

Postgres is PostgreSQL (and CockroachDB): $n placeholders.

func (Postgres) Name

func (Postgres) Name() string

Name returns "postgres".

func (Postgres) Placeholder

func (Postgres) Placeholder(n int) string

Placeholder returns "$n". A non-positive n is a statement builder's bug and panics: it would render invalid SQL.

func (Postgres) QuoteIdent

func (Postgres) QuoteIdent(name string) string

QuoteIdent quotes name per the SQL standard.

type SQLite

type SQLite struct{}

SQLite is SQLite: ?n placeholders.

func (SQLite) Name

func (SQLite) Name() string

Name returns "sqlite".

func (SQLite) Placeholder

func (SQLite) Placeholder(n int) string

Placeholder returns "?n"; a non-positive n panics, as for Postgres.

func (SQLite) QuoteIdent

func (SQLite) QuoteIdent(name string) string

QuoteIdent quotes name per the SQL standard.

Jump to

Keyboard shortcuts

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