model

package
v0.0.0-...-c63dae0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit    = 100
	DefaultMaxLimit = 1000
	DefaultMinLimit = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClampWithDefault

type ClampWithDefault struct {
	Min     uint
	Max     uint
	Default uint
}

type Config

type Config struct {
	Entities  []Entity `yaml:"entities"`
	Project   ProjectConfg
	Queries   QueriesConfig
	Paginator PaginatorConfig `yaml:"paginators"`
}

All paths are relative to that of the configuration file

func LoadConfig

func LoadConfig(logger *slog.Logger, path string) (Config, error)

type Entity

type Entity struct {
	Name                 string        // Name of the Entity used in user interface
	SqlcType             string        `yaml:"sqlc_type"` // Name of the sqlc generated type representing that table
	Table                string        // Name of the database table
	Select               []string      // unused
	Joins                []string      // Joins to added, form of '<table> on <cond>', `join` is automatically added
	Where                []string      // Additional where conditions `foo = bar`, they're all automatically ANDed
	PrimaryKey           string        `yaml:"primary_key"`         // name of the primary key column
	SortKeys             []SortColumn  `yaml:"sort_keys"`           // list of additional columns we can sort on
	DefaultSortColumn    string        `yaml:"default_sort_column"` // name of the default column to sort on, must be in SortKeys
	DefaultDirection     string        `yaml:"default_direction"`   // default order direction
	DefaultLimit         uint          `yaml:"default_limit"`       // by default only return this number of rows max
	RequiredExternalVals []ExternalVal `yaml:"provided_values"`     // name and type of fields required by the paginator which cannot be inferred from the request
}

Entity describes something we want to paginate. It's backed by one table with a bigint primary key and one or more sort columns. Primary key plus a sort column form a keyset that can be paginated over.

func (Entity) PaginatedType

func (e Entity) PaginatedType() string

func (Entity) PaginatorType

func (e Entity) PaginatorType() string

func (Entity) SortColumnByName

func (e Entity) SortColumnByName(name string) SortColumn

func (Entity) Validate

func (e Entity) Validate() []string

type ExternalVal

type ExternalVal struct {
	Name       string
	Type       string
	NotInQuery bool `yaml:"not_in_query"` // Parameter is added to the paginator, but not to the query
}

type Generator

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

func NewGenerator

func NewGenerator(logger *slog.Logger, config Config) *Generator

func (*Generator) Generate

func (g *Generator) Generate() error

type PaginatorConfig

type PaginatorConfig struct {
	Package string
	File    string
	// contains filtered or unexported fields
}

type ProjectConfg

type ProjectConfg struct {
	Module string // Base package of the module
	Root   string // Base directory, inferred from config file path if empty
}

type QueriesConfig

type QueriesConfig struct {
	File    string
	Package string // Package the generated packages go into

	Limit ClampWithDefault
	// contains filtered or unexported fields
}

type SortColumn

type SortColumn struct {
	Name             string
	Title            string
	DefaultDirection string `yaml:"default_direction"`
	Type             string // We need to know the type to parse and we need to know if it needs to be encoded
	Prefix           string
}

func (SortColumn) ColumnName

func (s SortColumn) ColumnName() string

Jump to

Keyboard shortcuts

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