models

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TableName    string
	ResourceName string
	PackageName  string
	DatabaseType string
	ModulePath   string
	CustomTypes  []types.TypeOverride
}

type FactoryField added in v1.0.0

type FactoryField struct {
	Name          string
	ArgumentName  string
	Type          string
	GoZero        string
	DefaultValue  string
	OptionName    string
	IsFK          bool
	IsTimestamp   bool
	IsID          bool
	IsAutoManaged bool
}

FactoryField represents a field in a factory

type GeneratedFactory added in v1.0.0

type GeneratedFactory struct {
	ModelName         string
	Package           string
	Fields            []FactoryField
	ModulePath        string
	StandardImports   []string
	ExternalImports   []string
	HasCreateFunction bool
	HasForeignKeys    bool           // True if there are 1+ FKs
	ForeignKeyFields  []FactoryField // All FK fields
	IDType            string         // "uuid.UUID", "int32", "int64", "string"
	IsAutoIncrementID bool           // True for serial/bigserial
}

GeneratedFactory represents a factory for a model

type GeneratedField

type GeneratedField struct {
	Name                    string
	Type                    string
	Comment                 string
	Package                 string
	SQLCType                string
	ConversionFromDB        string
	ConversionToDB          string
	ConversionToDBForUpdate string
	ZeroCheck               string
	IsForeignKey            bool
}

type GeneratedModel

type GeneratedModel struct {
	Name                 string
	PluralName           string // The pluralized form of Name for function names (respects --table-name override)
	SQLCModelName        string // The SQLC row struct name derived from the table name
	Package              string
	Fields               []GeneratedField
	StandardImports      []string
	ExternalImports      []string
	Imports              []string
	TableName            string
	TableNameOverride    string
	TableNameOverridden  bool
	ModulePath           string
	DatabaseType         string
	IDType               string          // "uuid.UUID", "int32", "int64", "string"
	IDGoType             string          // Same as IDType (for template clarity)
	IsAutoIncrementID    bool            // True for serial/bigserial
	HasSingleInsertParam bool            // True when SQLC won't create an InsertXxxParams struct
	SingleInsertField    *GeneratedField // The single field when HasSingleInsertParam is true
}

type Generator

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

func NewGenerator

func NewGenerator(databaseType string) *Generator

func (*Generator) Build

func (g *Generator) Build(cat *catalog.Catalog, config Config) (*GeneratedModel, error)

func (*Generator) BuildFactory added in v1.0.0

func (g *Generator) BuildFactory(cat *catalog.Catalog, config Config, genModel *GeneratedModel) (*GeneratedFactory, error)

BuildFactory generates factory metadata from a model

func (*Generator) GenerateFactoryFile added in v1.0.0

func (g *Generator) GenerateFactoryFile(factory *GeneratedFactory, templateStr string) (string, error)

GenerateFactoryFile renders a factory file from a template

func (*Generator) GenerateModel

func (g *Generator) GenerateModel(
	cat *catalog.Catalog,
	resourceName string,
	pluralName string,
	modelPath, sqlPath string,
	modulePath string,
	tableNameOverride string,
) error

func (*Generator) GenerateModelFile

func (g *Generator) GenerateModelFile(model *GeneratedModel, templateStr string) (string, error)

func (*Generator) GenerateModelFromMigrations

func (g *Generator) GenerateModelFromMigrations(
	tableName, resourceName string,
	migrationDirs []string,
	modelPath, sqlPath string,
	modulePath string,
) error

func (*Generator) GenerateQueriesOnlyContent

func (g *Generator) GenerateQueriesOnlyContent(
	resourceName string,
	pluralName string,
	table *catalog.Table,
	tableNameOverridden bool,
) (string, error)

GenerateQueriesOnlyContent generates SQL content using the queries_only.tmpl template. This is used for refreshing queries-only files.

func (*Generator) GenerateQueriesOnlyFile

func (g *Generator) GenerateQueriesOnlyFile(
	resourceName string,
	pluralName string,
	table *catalog.Table,
	sqlPath string,
	tableNameOverridden bool,
) error

GenerateQueriesOnlyFile generates a SQL file using the queries_only.tmpl template. This is used for lightweight query generation without a model layer.

func (*Generator) GenerateSQLContent

func (g *Generator) GenerateSQLContent(
	resourceName string,
	pluralName string,
	table *catalog.Table,
	tableNameOverridden bool,
) (string, error)

func (*Generator) GenerateSQLFile

func (g *Generator) GenerateSQLFile(
	resourceName string,
	pluralName string,
	table *catalog.Table,
	sqlPath string,
	tableNameOverridden bool,
) error

func (*Generator) RefreshQueries

func (g *Generator) RefreshQueries(
	cat *catalog.Catalog,
	resourceName, pluralName string,
	sqlPath string,
	tableNameOverridden bool,
) error

func (*Generator) RefreshQueriesOnly

func (g *Generator) RefreshQueriesOnly(
	cat *catalog.Catalog,
	resourceName, pluralName string,
	sqlPath string,
	tableNameOverridden bool,
) error

RefreshQueriesOnly refreshes a queries-only SQL file (without model layer).

func (*Generator) WriteFactoryFile added in v1.0.0

func (g *Generator) WriteFactoryFile(factory *GeneratedFactory, outputDir string) error

WriteFactoryFile writes a factory file to disk

type SQLData

type SQLData struct {
	ResourceName           string
	PluralName             string
	PluralResourceName     string // The pluralized form of ResourceName for query function names
	InsertColumns          string
	InsertPlaceholders     string
	UpdateColumns          string
	DatabaseType           string
	IDPlaceholder          string
	LimitOffsetClause      string
	NowFunction            string
	UpsertUpdateSet        string
	OrderByClause          string
	TableNameOverridden    bool
	IDType                 string // "uuid.UUID", "int32", "int64", "string"
	IsAutoIncrementID      bool   // True for serial/bigserial
	InsertColumnsNoID      string // Columns excluding id (for auto-increment)
	InsertPlaceholdersNoID string // Placeholders excluding id (for auto-increment)
}

type SimpleSQLData

type SimpleSQLData struct {
	ResourceName           string
	PluralName             string
	PluralResourceName     string
	InsertColumns          string
	InsertPlaceholders     string
	UpdateColumns          string
	IDPlaceholder          string
	UpsertUpdateSet        string
	IDType                 string // "uuid.UUID", "int32", "int64", "string"
	IsAutoIncrementID      bool   // True for serial/bigserial
	InsertColumnsNoID      string // Columns excluding id (for auto-increment)
	InsertPlaceholdersNoID string // Placeholders excluding id (for auto-increment)
}

SimpleSQLData is used for queries-only generation (no model layer). It treats all columns uniformly without special handling for timestamps.

Jump to

Keyboard shortcuts

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