govert

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2020 License: MIT Imports: 27 Imported by: 0

README

GoVert

A helper function generator to convert your models to your domain types easier.

GoVert is a fork of gqlgen-sqlboiler, an awesome file generator for SQL Boil and GraphQL. This library focuses less on the GraphQL side and more on the helper function generation.

Features:

  • Auto generate functions that map your domain types to your models, and back again. Stop writing the same boilerplate code, over and over again.
  • Custom return / domain types. Have
  • Custom primary keys. Generate custom functions that map builtin types (id, uint, string, etc.) or custom struct types to a number of utilities.
  • Go.mod support

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUnderlyingType

func GetUnderlyingType(typ reflect.Type) string

func HasStringPrimaryIDsInModels

func HasStringPrimaryIDsInModels(models []*Model) bool

func IsBuiltin

func IsBuiltin(typ reflect.Type) bool

func NameForDir

func NameForDir(dir string) string

NameForDir manually looks for package stanzas in files located in the given directory. This can be much faster than having to consult go list, because we already know exactly where to look.

func New

func New(output, backend, frontend Directory, opts ...Option) plugin.Plugin

func PkgAndType

func PkgAndType(name string) (string, string)

take a string in the form github.com/package/blah.Type and split it into package and type

func SanitizePackageName

func SanitizePackageName(pkg string) string

Types

type BoilerField

type BoilerField struct {
	Name             string
	PluralName       string
	Type             string
	IsForeignKey     bool
	IsRequired       bool
	IsArray          bool
	IsRelation       bool
	RelationshipName string
	Relationship     BoilerModel
}

type BoilerModel

type BoilerModel struct {
	Name                  string
	PluralName            string
	Fields                []*BoilerField
	HasOrganizationID     bool
	HasUserOrganizationID bool
	HasUserID             bool
}

func FindBoilerModel

func FindBoilerModel(models []*BoilerModel, modelName string) BoilerModel

func GetBoilerModels

func GetBoilerModels(dir string) []*BoilerModel

parseModelsAndFieldsFromBoiler since these are like User.ID, User.Organization and we want them grouped by modelName and their belonging fields.

type BoilerType

type BoilerType struct {
	Name string
	Type string
}

type ColumnSetting

type ColumnSetting struct {
	Name                  string
	RelationshipModelName string
	IDAvailable           bool
}

type Convert

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

func (*Convert) MutateConfig

func (m *Convert) MutateConfig(originalCfg *config.Config) error

func (*Convert) Name

func (m *Convert) Name() string

type ConvertConfig

type ConvertConfig struct {
	IsCustom         bool
	ToBoiler         string
	ToGraphQL        string
	GraphTypeAsText  string
	BoilerTypeAsText string
}

type Directory

type Directory struct {
	Directory string
	Package   string
}

type Enum

type Enum struct {
	Description string
	Name        string

	Values []*EnumValue
}

type EnumValue

type EnumValue struct {
	Description string
	Name        string
	NameLower   string
}

type Field

type Field struct {
	Name               string
	PluralName         string
	Type               string
	TypeWithoutPointer string
	IsNumberID         bool
	IsPrimaryNumberID  bool
	IsPrimaryID        bool
	IsRequired         bool
	IsPlural           bool
	ConvertConfig      ConvertConfig
	// relation stuff
	IsRelation bool
	// boiler relation stuff is inside this field
	BoilerField BoilerField
	// graphql relation ship can be found here
	Relationship *Model
	IsOr         bool
	IsAnd        bool

	// Some stuff
	Description  string
	OriginalType types.Type
	Tag          string
}

type Import

type Import struct {
	Alias      string
	ImportPath string
}

type Interface

type Interface struct {
	Description string
	Name        string
}

type Model

type Model struct {
	Name                  string
	PluralName            string
	BoilerModel           BoilerModel
	PrimaryKeyType        string
	Fields                []*Field
	IsNormal              bool
	IsInput               bool
	IsCreateInput         bool
	IsUpdateInput         bool
	IsNormalInput         bool
	IsPayload             bool
	IsWhere               bool
	IsFilter              bool
	IsPreloadable         bool
	PreloadArray          []Preload
	HasOrganizationID     bool
	HasUserOrganizationID bool
	HasUserID             bool
	HasStringPrimaryID    bool
	// other stuff
	Description string
	PureFields  []*ast.FieldDefinition
	Implements  []string
}

func GetModelsWithInformation

func GetModelsWithInformation(enums []*Enum, cfg *config.Config, boilerModels []*BoilerModel) []*Model

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

func PrimaryKeyCustom

func PrimaryKeyCustom(typ interface{}) Option

func PrimaryKeyInt

func PrimaryKeyInt() Option

func PrimaryKeyString

func PrimaryKeyString() Option

func PrimaryKeyUint

func PrimaryKeyUint() Option

type Preload

type Preload struct {
	Key           string
	ColumnSetting ColumnSetting
}

type Rewriter

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

func NewRewriter

func NewRewriter(importPath string) (*Rewriter, error)

func (*Rewriter) ExistingImports

func (r *Rewriter) ExistingImports(filename string) []Import

func (*Rewriter) GetMethodBody

func (r *Rewriter) GetMethodBody(structname string, methodname string) string

func (*Rewriter) MarkStructCopied

func (r *Rewriter) MarkStructCopied(name string)

func (*Rewriter) RemainingSource

func (r *Rewriter) RemainingSource(filename string) string

type Template

type Template struct {
	Backend             Directory
	Frontend            Directory
	HasStringPrimaryIDs bool
	PackageName         string
	Interfaces          []*Interface
	Models              []*Model
	Enums               []*Enum
	Scalars             []string
	PrimaryKey          reflect.Type
}

Jump to

Keyboard shortcuts

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