luimagen

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package luimagen @notice Generates a table's CRUD layer: given the table's fields it writes the Go model struct, appends the matching GraphQL SDL to a schema file, runs the consumer's own `go tool gqlgen generate`, and fills in the five resulting resolver stubs with calls to luima.Get/List/Create/Update/Delete.

@dev A separate package from the module root, not re-exported through luima.go — importing github.com/ulas96/luima never pulls this in, and Config/Mount/Run gain no new surface. See docs/luimagen.md §1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts Options) error

Generate @notice Builds the model struct for opts.Type from opts.Fields, appends its SDL to opts.SchemaFile, runs `go tool gqlgen generate` in opts.Dir, and patches the five stubs it writes to call luima.Get/List/Create/Update/Delete. See docs/luimagen.md §2 for why each step is shaped the way it is.

@dev Silent on success and side-effecting only through the files it writes plus stdout/stderr inherited by the gqlgen subprocess — never fmt.Print. A library call has no business deciding whether its caller wants progress lines; cmd/luimagen prints them instead. @dev A failed call can leave the model file and/or appended SDL on disk — see docs/luimagen.md §2.4 ("Recovering from a failed run") for why that's deliberate and how to clean up before retrying. @param opts Options{Type: "User", Fields: [...]} is enough when the module follows the layout docs/gqlgen-contract.md documents; every other field overrides one default. @return error wraps whichever stage failed — building the table, writing the model, writing SDL, running gqlgen, or patching stubs — with enough context to tell them apart

Types

type Field

type Field struct {
	Name string // Go field name, e.g. "PersonalID"
	Type string // Go type as it should appear in the generated struct: string, int, float64, bool, or a slice of one of those, e.g. "[]string"
	PK   bool   // true for exactly one field
	// Column is the SQL column name; default snakeCase(Name), which is go-pg's own convention.
	// Set it when the table's column is not what that derives — most often a run of capitals with
	// no lower-case neighbour, where go-pg's rule inserts no separator at all: URLID becomes
	// urlid, and the column is almost certainly url_id. luimagen does not create the table, so a
	// derived name that disagrees with it compiles fine and fails on the first query.
	Column string
}

Field @notice One column of the table Generate builds.

@dev Name is where the GraphQL field name comes from (lowerFirst), and where the SQL column name comes from unless Column overrides it. Exactly one Field in Options.Fields must have PK set. There is no GraphQL field-name override; see docs/luimagen.md §4.

type Options

type Options struct {
	Type         string  // Go/GraphQL type name, e.g. "User" — required
	Fields       []Field // the table's columns, in declaration order — required, exactly one with PK: true
	Table        string  // SQL table name; default snake_case(Type)+"s", e.g. "users" — set explicitly for anything irregular (a prefix, non-English pluralization)
	Dir          string  // the consumer module's root: where `go tool gqlgen generate` runs, and what ModelDir/SchemaFile/ResolverFile are relative to; default "."
	ModelDir     string  // directory to write the model struct into, relative to Dir; default "graph/model"
	SchemaFile   string  // schema file to append the generated SDL to, relative to Dir; default "graph/schema.graphqls"
	ResolverFile string  // resolver file gqlgen writes stubs into, relative to Dir; default: SchemaFile with its extension replaced by ".resolvers.go"
	ModelPkg     string  // import name of the model package as used in resolver code, e.g. "model1" when gqlgen aliased it; default "model". Not the generated file's package clause — that is read from ModelDir
}

Options @notice Configures one Generate call for one table.

@dev Every path field defaults to the layout docs/gqlgen-contract.md documents, matching Config's own "zero means unset, not off" convention (CLAUDE.md) — Options{Type: ..., Fields: ...} is enough for a consumer whose module follows that layout.

Jump to

Keyboard shortcuts

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