dialect

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package dialect provides cross-cutting helpers that vary between SQL engines but are otherwise reusable by every domain store. A store wires in one implementation (Postgres, SQLite, ...) and delegates the small set of engine-specific decisions to it, so shared SQL fragments stay portable.

The set of decisions is intentionally narrow — only add to the interface when a real, second engine forces a difference.

Usage

d := dialect.Postgres{} // or dialect.SQLite{}, chosen per store

var buf bytes.Buffer
buf.WriteString("SELECT id, name FROM widgets ORDER BY id")
d.Paginate(&buf) // appends the engine's pagination clause

// Bind :offset and :rows_per_page in the params passed to
// dbx.NamedQuerySlice / NamedQueryStruct.
params := map[string]any{"offset": 0, "rows_per_page": 50}

Implementations

  • Postgres: SQL:2008 " OFFSET :offset ROWS FETCH NEXT :rows_per_page ROWS ONLY".
  • SQLite: " LIMIT :rows_per_page OFFSET :offset" (also valid for MySQL).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	// Name reports a short identifier for the engine (for logging only).
	Name() string

	// Paginate appends a pagination clause to buf. The clause consumes the named
	// bind variables ":offset" and ":rows_per_page", which the caller must supply
	// in the parameter map.
	Paginate(buf *bytes.Buffer)
}

Dialect describes the engine-specific behavior a store needs in order to compose portable SQL from shared fragments.

type Postgres

type Postgres struct{}

Postgres is the Dialect for PostgreSQL. It uses the SQL:2008 standard OFFSET / FETCH NEXT pagination form.

func (Postgres) Name

func (Postgres) Name() string

Name implements Dialect.

func (Postgres) Paginate

func (Postgres) Paginate(buf *bytes.Buffer)

Paginate implements Dialect.

type SQLite

type SQLite struct{}

SQLite is the Dialect for SQLite. It uses the LIMIT / OFFSET pagination form, which MySQL and modern Postgres also accept. It exists as a second, deliberately different dialect so the engine-specific seam stays visible and exercised.

func (SQLite) Name

func (SQLite) Name() string

Name implements Dialect.

func (SQLite) Paginate

func (SQLite) Paginate(buf *bytes.Buffer)

Paginate implements Dialect.

Jump to

Keyboard shortcuts

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