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.