generate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package generate implements code generation for repository types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRepository

func GenerateRepository(options Options) ([]byte, error)

GenerateRepository generates a repository implementation based on the given options. It returns the generated source code or an error.

Types

type FieldMapping

type FieldMapping struct {
	Field  string
	Column string
	Type   string
	Opts   FieldOptions
}

FieldMapping defines the mapping of a single struct field.

func (*FieldMapping) ValuesGetterName added in v0.2.0

func (f *FieldMapping) ValuesGetterName() string

ValuesGetterName returns the name of the Values.Get* method to invoke to obtain a value assignable to the target field.

type FieldOptions

type FieldOptions struct {
	ID bool
}

FieldOptions defines the additional options to be marked on field.s

type Options

type Options struct {
	// Name of the go file containing the entity definition.
	Filename string
	// Name of the type (as declared in the given file) to detect mappings for,
	EntityName string
	// Optional name of the table to map the entity to.
	// Defaults to a SQL converted name of the entity.
	TableName string
	// Optional name of the go package containing the generated repo.
	// Defaults to the entity's package name.
	RepoPackage string
	// Optional name of the repo type.
	// Defaults to the entity name with a `Repo` suffix.
	RepoName string
	// Flag indicating if the repo should only provide finder
	// methods and do not support modifications.
	ReadOnly bool
}

Options defines the generation options.

type StructMapping

type StructMapping struct {
	Package string
	Name    string
	Fields  []FieldMapping
}

StructMapping defines how a single struct is mapped.

func (*StructMapping) ID

func (s *StructMapping) ID() *FieldMapping

ID returns the field mapping defining the primary key or nil if no such mapping is defined.

Jump to

Keyboard shortcuts

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