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

catalog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package catalog is the catalog half of the smart-comments plugin: it indexes PostGraphile-style tags parsed from database COMMENTs and applies the ones with a structural representation in the introspect.Catalog — @omit on whole objects, @omit create/update/delete → privilege flags, @primaryKey / @unique / @foreignKey synthesis, @notNull / @nullable, and @filterable / @sortable as a synthetic index. Products embed the Hook and add their naming (InflectionHook) and surface (schema/API hook) halves on top of the same Index.

Index

Constants

View Source
const (
	Name = "smart-comments"
	// Priority 50: the CatalogHook shapes the catalog before other plugins
	// read it, and the products' naming halves apply @name before naming
	// plugins (simple-names, 100) format.
	Priority = 50
)

Name and Priority of the smart-comments plugin (shared by both products' wrappers so plugins.disabled works the same everywhere).

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook is the CatalogHook. The tag index is rebuilt on every TransformCatalog (watch-mode rebuilds reuse the instance) and is exposed through Index for the products' inflection/surface halves.

func New

func New() *Hook

New returns a Hook logging to slog.Default().

func (*Hook) Index

func (h *Hook) Index() *Index

Index returns the tag index built by the last TransformCatalog.

func (*Hook) Name

func (h *Hook) Name() string

func (*Hook) Priority

func (h *Hook) Priority() int

func (*Hook) SetLogger

func (h *Hook) SetLogger(l *slog.Logger)

SetLogger replaces the warning logger.

func (*Hook) TransformCatalog

func (h *Hook) TransformCatalog(_ context.Context, c *introspect.Catalog) error

TransformCatalog applies every tag with a catalog-level representation.

type Index

type Index struct {
	Tables      map[string]smarttags.Tags // "schema.table"
	TablesBy    map[string]smarttags.Tags // "table"
	Columns     map[string]smarttags.Tags // "schema.table.column"
	ColumnsBy   map[string]smarttags.Tags // "table.column"
	Enums       map[string]smarttags.Tags // "schema.enum"
	EnumsBy     map[string]smarttags.Tags // "enum"
	Functions   map[string]smarttags.Tags // "schema.function"
	FunctionsBy map[string]smarttags.Tags // "function"
	Constraints map[string]smarttags.Tags // "schema.constraint"
}

Index holds the parsed tags of every commented catalog object. The *By maps are schema-less fallbacks for call sites that don't carry the pg schema; an ambiguous name (same table name in two schemas) maps to nil. The Constraints map is also written by the Hook when a @foreignKey value carries |@fieldName / |@foreignFieldName segments.

func BuildIndex

func BuildIndex(c *introspect.Catalog) *Index

BuildIndex parses and indexes the smart tags of every commented object.

func (*Index) Column

func (ix *Index) Column(schema, table, column string) smarttags.Tags

Column resolves a column's tags (schema-less fallback as Table).

func (*Index) Constraint

func (ix *Index) Constraint(schema, constraint string) smarttags.Tags

Constraint resolves a constraint's tags; constraints are always schema-qualified. Empty name → nil.

func (*Index) Enum

func (ix *Index) Enum(schema, name string) smarttags.Tags

Enum resolves an enum type's tags (schema-less fallback as Table).

func (*Index) Function

func (ix *Index) Function(schema, name string) smarttags.Tags

Function resolves a function's tags (schema-less fallback as Table).

func (*Index) RenamedColumn

func (ix *Index) RenamedColumn(schema, table, column string) string

RenamedColumn returns the @name of a column, or the column itself.

func (*Index) RenamedColumns

func (ix *Index) RenamedColumns(schema, table string, cols []string) []string

RenamedColumns maps RenamedColumn over cols.

func (*Index) RenamedTable

func (ix *Index) RenamedTable(schema, table string) string

RenamedTable returns the @name of a table, or the table itself.

func (*Index) Table

func (ix *Index) Table(schema, table string) smarttags.Tags

Table resolves tags by "schema.table", falling back to the schema-less index when the call site did not carry the pg schema.

Jump to

Keyboard shortcuts

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