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

model

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package model reads one `.sql` file as a model: a header, a query, and the name the two of them make.

THE CONFIG IS A COMMENT, so the file stays valid SQL. It opens in an editor with highlighting, it runs in a console by hand, and `psql -f` executes it. That is the whole reason the header is not front matter: a model you cannot paste into a client is a model you debug twice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Materialisation

type Materialisation string

Materialisation is what a model becomes in the warehouse.

const (
	View  Materialisation = "view"
	Table Materialisation = "table"

	// Incremental is a TABLE that is added to rather than rebuilt.
	//
	// It is a third value and not a flag on Table, because the three differ
	// in what Build emits, in whether the row count means anything, and in
	// whether the warehouse is asked a question before the statement is
	// written. A boolean beside `table` would make every switch read
	// `Table && !incremental`.
	Incremental Materialisation = "incremental"
)

type Model

type Model struct {
	// Schema and Name come from the PATH and never from the header:
	// `models/<schema>/<name>.sql` is `<schema>.<name>`. Two places to say
	// where a model lands is one place for them to disagree.
	Schema string
	Name   string

	Materialised Materialisation

	// UniqueKey and Watermark belong to an INCREMENTAL model and to nothing
	// else. Both are required there and both are refused elsewhere -- see
	// Parse, which says why neither has a default.
	UniqueKey []string
	Watermark string

	Tests []Test
	// DependsOn is the explicit override for an edge the extractor cannot
	// see -- SQL built at runtime, or one of the forms refs names as its
	// limits. Added to what was inferred, never instead of it.
	DependsOn []string

	// SQL is the query with the header still in it. The header is a comment,
	// so the warehouse ignores it and the file that ran is the file on disk.
	SQL string
}

Model is one file, read.

func Parse

func Parse(path string, content []byte) (Model, error)

Parse reads one model.

`path` is both the name in every error and where the model's identity comes from, so it has to be the path as the project sees it.

func (Model) Ref

func (m Model) Ref() string

Ref is `<schema>.<name>`, which is how a model is named everywhere else.

type Test

type Test struct {
	Kind    string
	Columns []string
	// Values is `accepted_values`' list; To and Field are `relationships`'.
	Values []string
	To     string
	Field  string
}

Test is one assertion about a model, as a name and the columns it is about.

Jump to

Keyboard shortcuts

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