codegen

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package codegen provides model generation from database schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(c *config.Config) error

Types

type Conflict

type Conflict struct {
	Key   string // constant suffix, e.g. "TenantIDEmail"
	Value string // CONFLICT (tenant_id, email) DO UPDATE
}

Conflict is an upsert conflict target of the generated model.

type Excluded

type Excluded struct {
	Key   string // constant suffix, e.g. "Subject"
	Value string // subject = EXCLUDED.subject
}

Excluded is one assignment for the SET clause of an upsert.

type Field

type Field struct {
	Imports      []Import // imports required by the field type
	Name         string   // field name, e.g: ID
	Type         string   // type, e.g: string | int32 | int8
	Tag          string   // tag, e.g: `bun:"id,pk,autoincrement,notnull" json:"id,omitempty"`
	Comments     []string // comments e.g: user id
	ColumnName   string   // db column name e.g: id
	Kind         string   // logic type: NUMERIC |STRING | ...
	IsArithmetic bool     // arithmetic expressions make sense for the field
	IsPrimary    bool     // is primary key
	IsNullable   bool     // is nullable
	IsCustom     bool     // is custom type
	IsRelation   bool     // is relation
}

func NewCustomField

func NewCustomField(fieldName string, customTable *config.CustomTable, n *naming.Naming, imports []*config.Import) *Field

func NewField

func NewField(c *schema.Column, customTable *config.CustomTable, driver string, n *naming.Naming, imports []*config.Import) (*Field, error)

type Import

type Import struct {
	Path  string
	Alias string
}

type Index

type Index struct {
	Key   string
	Value string
}

type Model

type Model struct {
	Version             string     // bake version
	Module              string     // module path
	Package             string     // package name
	Imports             [][]Import // imports
	Driver              string     // driver name
	BunModel            string     // bun.BaseModel
	Table               string     // table name
	Model               string     // model name
	Alias               string     // model alias
	Comments            []string   // model comments
	Fields              []*Field   // fields
	Indexes             []Index    // indexes
	Conflicts           []Conflict // upsert conflict targets
	Excluded            []Excluded // upsert SET assignments
	Timezone            string     // timezone
	CreatedAtType       string     // created_at type
	UpdatedAtType       string     // updated_at type
	DeletedAtType       string     // deleted_at type
	HasField            bool       // has at least one field
	HasNullable         bool       // has a nullable field
	HasString           bool       // has a STRING field
	HasOrdered          bool       // has an ordered field (string/numeric/time)
	HasOrderedNonString bool       // has a numeric or time field
	HasEquatable        bool       // has an equatable field (numeric/string/bool/time/enum)
	HasRelation         bool       // has a relation field
	HasArithmetic       bool       // has a non-primary numeric field
	HasTime             bool       // has a TIME field
}

func NewCustomStruct

func NewCustomStruct(cfg *config.Config, st *config.CustomStruct) *Model

NewCustomStruct creates Model from a single custom struct configuration.

func NewModel

func NewModel(t *schema.Table, db *config.DB, cfg *config.Config, n *naming.Naming) (*Model, error)

type Tag

type Tag config.Tag

func NewTag

func NewTag(key string, name string, options ...string) *Tag

func (*Tag) String

func (t *Tag) String() string

type Tags

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

func NewTags

func NewTags(tags ...*Tag) *Tags

func (*Tags) Add

func (t *Tags) Add(tags ...*Tag) *Tags

func (*Tags) String

func (t *Tags) String() string

Jump to

Keyboard shortcuts

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