Help us shape the future of Go! Take the 2026 Go Developer Survey

dialect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package dialect is the part of building a model that differs per warehouse.

ONE INTERFACE WITH A CONFORMANCE SUITE, written while there was a single implementation. That order is the whole point: a second dialect added against an interface nobody tests agrees with the first wherever the author happened to look and differs everywhere else, and the difference is found by a consumer. Here it is found by `go test`.

What is NOT in here is as deliberate as what is. There is no "quote an identifier", because this package refuses a name that would need quoting instead -- see the Postgres dialect's Build for why. There is no "begin a transaction", because BigQuery does not put DDL in one and an interface that lies about that would be worse than two honest orderings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	// Exec runs one statement. DDL, so nothing is returned.
	Exec(ctx context.Context, statement string) error

	// Scalar runs a query of one row and one column. A query matching no row
	// returns nil, nil -- that is "nothing is there", which is an ANSWER on
	// this path and not a failure.
	Scalar(ctx context.Context, query string) (any, error)

	// Target names a relation the way the CATALOG does:
	// `bigquery://project/dataset/table`, `postgres://database/schema/table`.
	//
	// ON Conn AND NOT ON Dialect, because only a live connection knows the
	// first segment: the project for BigQuery, the database for Postgres,
	// and the latter is inside a DSN this package never sees in one piece.
	//
	// It is what puts a model on `/data`. The engine takes it on a `landed`
	// line and refuses anything that does not match its own rule -- counting
	// the refusal rather than failing the step, deliberately, because a
	// target the engine repaired would be a target the engine inferred. A
	// wrong one here is therefore a model that builds, reports success and
	// never appears, which is why the conformance suite asserts its shape.
	Target(ref string) string

	Close(ctx context.Context) error
}

Conn is the little a warehouse has to do.

Two methods, and they are the two the build loop needs: run a statement, and read one value back. A driver's own richer surface stays behind its dialect, where it belongs -- the loop must not learn what a pgx.Rows is.

type Dialect

type Dialect interface {
	// Name is what `--dialect` is given, and it is also the name the
	// reference extractor is given: a project cannot read its SQL as one
	// dialect and build it as another.
	Name() string

	// Open connects. The DSN comes from an environment variable named in the
	// command line, never from a file -- a connection string carries a
	// password and a project directory is in git.
	Open(ctx context.Context, dsn string) (Conn, error)

	// EnsureSchema is run before the models of that schema, and has to be
	// safe to run when the schema is already there.
	EnsureSchema(schema string) []string

	// KindOf is a query whose single value is "table", "view" or NULL.
	KindOf(ref string) string

	// Literal is a Go string as this warehouse's SQL spells it, quotes
	// included.
	//
	// ON THE INTERFACE BECAUSE IT MEASURABLY DIFFERS, and for no other
	// reason -- with one backslash in the statement, on 2026-10-08:
	//
	//	postgres   SELECT LENGTH('a\bc')  ->  4   a backslash is a character
	//	bigquery   SELECT LENGTH('a\bc')  ->  3   \b is a backspace
	//
	// A value a consumer wrote in an `accepted_values` test therefore means
	// two different things depending on where the project runs, and the
	// check built from it would pass against data it should refuse.
	Literal(s string) string

	// Build is every statement that turns the model into what its header
	// says, in order, given what is in the warehouse NOW.
	Build(m model.Model, current Kind) ([]string, error)
}

Dialect is one warehouse's half of building a model.

type Kind

type Kind string

Kind is what a relation IS in the warehouse right now.

Build is given it, because "create or replace" is three different statements depending on the answer and every dialect has to ask.

const (
	// Absent is nothing of that name.
	Absent Kind = ""
	Table  Kind = "table"
	View   Kind = "view"
)

func KindFrom

func KindFrom(v any) Kind

KindFrom reads what Scalar returned from a KindOf query.

Here rather than in each dialect because the three answers are the same three everywhere, and a driver that hands back []byte where another hands back string is not a dialect difference -- it is a driver difference, and turning it into a Kind twice is how the two drift.

Directories

Path Synopsis
Package bigquery builds models on Google BigQuery.
Package bigquery builds models on Google BigQuery.
Package dialecttest is the suite every dialect has to pass.
Package dialecttest is the suite every dialect has to pass.
Package postgres builds models on PostgreSQL.
Package postgres builds models on PostgreSQL.

Jump to

Keyboard shortcuts

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