Documentation
¶
Overview ¶
Package generate implements code generation for repository types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRepository ¶
GenerateRepository generates a repository implementation based on the given options. It returns the generated source code or an error.
Types ¶
type ByteSlice ¶ added in v0.3.0
type ByteSlice struct {
}
ByteSlice implements a Type that describes a slice of bytes, i.e. []byte.
func (*ByteSlice) AssignNonNil ¶ added in v0.3.0
type FieldMapping ¶
type FieldMapping struct {
Field string
Column string
Type Type
Opts FieldOptions
}
FieldMapping defines the mapping of a single struct field.
type FieldOptions ¶
type FieldOptions struct {
// Flag indicating that this field is mapped to the primary key column
ID bool
// Flag indicating whether values mapped to this field can be null.
Nullable bool
}
FieldOptions defines the additional options to be marked on field.s
type NamedType ¶ added in v0.3.0
type NamedType struct {
Name string
}
NamedType is an implementation of Type which uses a bare name to refer to a type, such as string, int or time.Time.
func (*NamedType) AssignNonNil ¶ added in v0.3.0
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 PointerType ¶ added in v0.3.0
type PointerType struct {
NamedType
}
func (*PointerType) AssignNonNil ¶ added in v0.3.0
func (p *PointerType) AssignNonNil(assignVar, okVar, valuesExpr, columnExpr string) string
func (*PointerType) Expr ¶ added in v0.3.0
func (p *PointerType) Expr() string
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.
type Type ¶ added in v0.3.0
type Type interface {
// Expr returns a string containing a Go expression to define
// a variable or parameter of this type.
Expr() string
// Returns a Go statement that obtains the column value from
// a depot.Values object and assigns it to a variable and a
// boolean flag indicating success.
AssignNonNil(assignVar, okVar, valuesExpr, columnExpr string) string
}
Type represents a mapped field's type. It provides methods to generate code to interact with the field.