project

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package project reads a directory of models and works out the order.

An edge is INFERRED from the SQL and then shown, which is the shape the spike's verdict asked for by name: the extractor reads 99.3% of real Postgres and nobody should find the other 0.7% at three in the morning. `brevis-sql graph` prints what was inferred, and `depends_on:` overrides it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

type Function struct {
	Schema, Name string
	// Path is as the project sees it, so an error names what somebody typed.
	Path string
	SQL  string
}

Function is one SQL function the project owns.

THE SPIKE'S VERDICT PUT THESE IN M2 BY NAME. The most used macros in a real 625-model dbt project are expressions -- `trim_make_empty_string_null` at 1,674 uses, `generate_surrogate_key` at 268 -- and with those as SQL functions, 53% of its models need no template at all. That is the premise of this tool holding for half of a project nobody wrote for it.

The body is run VERBATIM and nothing here parses it. A function's text is `create or replace function …`, which is already idempotent in both dialects, and a tool that rewrote it would be guessing at a language it has no reason to read.

func (Function) Ref

func (f Function) Ref() string

Ref is `<schema>.<name>`, the same shape a model's is.

type Project

type Project struct {
	Models map[string]model.Model // by Ref(), `<schema>.<name>`
	// Edges[a] are the models a reads. Only models: a reference to something
	// this project does not define is a SOURCE, and sources have no edges
	// because nothing here builds them.
	Edges   map[string][]string
	Sources map[string][]string // by model, the references that are not models

	// Functions are `functions/<schema>/<name>.sql`, in path order. They
	// are run BEFORE the models and they are not models: no header, no
	// materialisation, no tests, no place in the graph.
	Functions []Function
}

Project is every model under a root, with the edges between them.

func Load

func Load(root, dialect string) (*Project, error)

Load reads every `.sql` under root/models.

func (*Project) Order

func (p *Project) Order() ([]string, error)

Order is the models in an order where everything a model reads comes first.

A cycle is refused NAMING THE RING. "there is a cycle" sends somebody to read every model; the ring sends them to two.

func (*Project) Select

func (p *Project) Select(expr string) ([]string, error)

Select narrows to the models a `--select` expression names.

`name` is one model; `name+` is it and everything downstream of it, which is the question somebody actually asks: "I changed this, what else moves".

Jump to

Keyboard shortcuts

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