header

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package header reads the declaration header of an authored SQL file: the leading run of blank lines, plain "--" comments (prose, skipped), and "--|" declaration lines of the form "--| key: value", ending at the first line that is none of those. The marker makes a declaration definite: a "--|" line that is not a declaration is an error, and a plain comment is never one. The header is the loader's; End marks where the body the engine receives begins. The package knows no keys; each consumer decides which keys it accepts and what their values mean. query reads tier, native, transaction, key, and field. migrate reads transaction; sqlint reads what each role's checks need.

Index

Constants

View Source
const Marker = "--|"

Marker opens a declaration line. It is a comment to every engine that reads "--" without requiring whitespace after it, and it is never sent: the header is the loader's, and a consumer hands the engine the body.

Variables

This section is empty.

Functions

This section is empty.

Types

type Declaration

type Declaration struct {
	Key   string
	Value string
	Line  int
}

Declaration is one "--| key: value" declaration of the header, with the 1-based number of the line that opens it for a consumer's error messages. A value folded across several lines is joined into one Value.

type Header struct {
	// contains filtered or unexported fields
}

Header is the declarations of one file, in file order, and where the body begins. A key may repeat; "field" does, once per column.

func Parse

func Parse(text string) (Header, error)

Parse reads the header from text: the leading run of lines that are blank, plain "--" comments (prose, skipped), or "--|" declarations. The header ends at the first line that is none of those. A declaration line that is not "--| key: value", or a declaration after the body has begun, is an error.

A long value folds across lines: "--| [key]: more" repeats the key of the declaration it continues in brackets, and Parse appends its text to that declaration's value with a single space between the pieces. A fold continues the declaration on the line immediately above it, so a blank line, a prose line, or another declaration ends the run a fold may join. A fold whose key is not the one it continues, or that continues nothing, is an error.

func (Header) All

func (h Header) All(key string) []string

All returns the values of every declaration with key, in order.

func (Header) Declarations

func (h Header) Declarations() []Declaration

Declarations returns every declaration in file order.

func (Header) End

func (h Header) End() int

End returns the byte offset at which the body begins: the start of the first line that is neither a comment nor blank, or the length of the text when there is no body. A consumer sends text[End():] to the engine and scans it for what only the body may contain.

func (Header) Get

func (h Header) Get(key string) (string, bool)

Get returns the value of the first declaration with key, and whether one exists.

func (Header) Keys

func (h Header) Keys() []string

Keys returns the distinct keys in order of first appearance, so a consumer can reject the ones it does not know.

Jump to

Keyboard shortcuts

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