smarttags

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package smarttags parses PostGraphile-style "smart comments": lines at the start of a database COMMENT beginning with '@' are machine-readable tags, everything after the first non-tag line is the human description.

COMMENT ON TABLE users IS E'@name people\n@omit delete\nA user of the app.';

parses to {name: ["people"], omit: ["delete"]} plus "A user of the app.". The parser is shared by the smart-comments and advanced-filters plugins so both read the same syntax from the same catalog comments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitList

func SplitList(v string) []string

SplitList splits a tag value on commas and whitespace, dropping empties — the list form shared by @omit, @primaryKey, and @unique values.

func Strip

func Strip(comment string) string

Strip returns the comment with any leading smart-tag lines removed.

Types

type Tags

type Tags map[string][]string

Tags maps a tag name to its values, one entry per occurrence in the comment; a bare tag (no value) contributes an empty string. A nil Tags is valid and empty.

func Parse

func Parse(comment string) (Tags, string)

Parse splits a comment into its smart tags and the remaining description. Comments with no leading '@' line are returned unchanged with nil tags.

func (Tags) All

func (t Tags) All(name string) []string

All returns every value of the tag in order (nil when absent).

func (Tags) First

func (t Tags) First(name string) string

First returns the first non-empty value of the tag, or "".

func (Tags) Has

func (t Tags) Has(name string) bool

Has reports whether the tag occurs at least once.

func (Tags) Omits

func (t Tags) Omits() (actions map[string]bool, everything bool)

Omits collects the actions named across all @omit occurrences (lowercased, split on commas and whitespace: "@omit create, update"). A bare @omit sets everything instead: the object is omitted entirely.

PostGraphile-V5-style @behavior tags contribute too: their negative tokens map onto omit actions (-insert -> create, -update -> update, -delete -> delete, -select -> read, -filter -> filter, -order -> order); other tokens are ignored.

Jump to

Keyboard shortcuts

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