generator

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package generator provides tools to generate ObjectBox entity bindings between GO structs & ObjectBox schema

Index

Constants

View Source
const Version = 5

Version specifies the current generator version. It is used to validate generated code compatibility and is increased when there are changes in the generated code. Internal generator changes that don't change the output do not cause an increase.

Variables

This section is empty.

Functions

func BindingFile

func BindingFile(sourceFile string) string

BindingFile returns a name of the binding file for the given entity file.

func Clean added in v1.1.0

func Clean(path string) error

Clean removes generated files in the given path. Removes *.obx.go and objectbox-model.go but keeps objectbox-model.json

func ModelFile

func ModelFile(modelInfoFile string) string

ModelFile returns the model GO file for the given JSON info file path

func ModelInfoFile

func ModelInfoFile(dir string) string

ModelInfoFile returns the model info JSON file name in the given directory

func Process

func Process(sourceFile string, options Options) error

Process is the main API method of the package it takes source file & model-information file paths and generates bindings (as a sibling file to the source file)

Types

type Annotation

type Annotation struct {
	Value string
}

Annotation is a tag on a struct-field

type Binding

type Binding struct {
	Package  *types.Package
	Entities []*Entity
	Imports  map[string]string
	// contains filtered or unexported fields
}

Binding contains information about the processed set of Entities

type Entity

type Entity struct {
	Identifier
	Name           string
	Fields         []*Field // the tree of struct fields (necessary for embedded structs)
	Properties     []*Property
	IdProperty     *Property
	LastPropertyId modelinfo.IdUid
	Relations      map[string]*StandaloneRelation
	Annotations    map[string]*Annotation
	// contains filtered or unexported fields
}

Entity holds the model information necessary to generate the binding code

func (*Entity) HasLazyLoadedRelations added in v1.0.0

func (entity *Entity) HasLazyLoadedRelations() bool

HasLazyLoadedRelations called from the template.

func (*Entity) HasNonIdProperty

func (entity *Entity) HasNonIdProperty() bool

HasNonIdProperty called from the template. The goal is to void GO error "variable declared and not used"

func (*Entity) HasRelations added in v0.9.0

func (entity *Entity) HasRelations() bool

HasRelations called from the template.

type Field added in v0.9.0

type Field struct {
	Entity             *Entity // parent entity
	Name               string
	Type               string
	IsPointer          bool
	Property           *Property // nil if it's an embedded struct
	Fields             []*Field  // inner fields, nil if it's a property
	SimpleRelation     *Relation
	StandaloneRelation *StandaloneRelation // to-many relation stored as a standalone relation in the model
	IsLazyLoaded       bool                // only standalone (to-many) relations currently support lazy loading
	// contains filtered or unexported fields
}

Field is a field in an entity-struct. Not all fields become properties (e.g. to-many relations don't have a property)

func (*Field) HasLazyLoadedRelations added in v1.0.0

func (field *Field) HasLazyLoadedRelations() bool

HasLazyLoadedRelations called from the template.

func (*Field) HasPointersInPath added in v1.1.0

func (field *Field) HasPointersInPath() bool

HasPointersInPath checks whether there are any pointer-based fields in the path. Called from the template.

func (*Field) HasRelations added in v0.9.0

func (field *Field) HasRelations() bool

HasRelations called from the template.

func (*Field) IsId added in v0.9.0

func (field *Field) IsId() bool

IsId returns true if the given field is an ID. Called from the template.

func (*Field) Path added in v1.1.0

func (field *Field) Path() string

Path returns full path to the field (in embedded struct) called from the template

type Identifier added in v0.9.0

type Identifier struct {
	Id  id
	Uid uid
}

Identifier combines DB ID and UID into a single structure

type Index

type Index struct {
	Identifier
}

Index holds information for creating an indexed field in DB

type Options added in v0.9.0

type Options struct {
	ModelInfoFile string
	ByValue       bool
	Rand          *rand.Rand
}

Options provide configuration for the generator

type Property

type Property struct {
	Identifier
	Name        string // prefixed name (unique)
	ObName      string // name of the field in DB
	Annotations map[string]*Annotation
	ObType      int

	GoType    string
	FbType    string
	IsPointer bool
	Relation  *Relation
	Index     *Index
	Converter *string

	// type casts for named types
	CastOnRead  string
	CastOnWrite string

	Field *Field // actual code field this property represents
	// contains filtered or unexported fields
}

Property represents a mapping between a struct field and a DB field

func (*Property) AnnotatedType added in v1.1.0

func (property *Property) AnnotatedType() string

AnnotatedType returns "type" annotation value

func (*Property) FbSlot

func (property *Property) FbSlot() int

FbSlot is called from the template. It calculates flatbuffers slot number.

func (*Property) FbvTableOffset

func (property *Property) FbvTableOffset() uint16

FbvTableOffset calculates flatbuffers vTableOffset. Called from the template.

func (*Property) IsId added in v1.1.0

func (property *Property) IsId() bool

IsId returns true if the given field is an ID. Called from the template.

func (*Property) ObFlagsCombined added in v1.0.0

func (property *Property) ObFlagsCombined() int

ObFlagsCombined called from the template

func (*Property) ObTypeString added in v1.0.0

func (property *Property) ObTypeString() string

ObTypeString is called from the template

func (*Property) Path added in v0.9.0

func (property *Property) Path() string

Path is called from the template. It returns full path to the property (in embedded struct).

func (*Property) TplReadValue added in v1.1.0

func (property *Property) TplReadValue(objVar, castType string) string

TplReadValue returns a code to read the property value on a given object.

func (*Property) TplSetAndReturn added in v1.1.0

func (property *Property) TplSetAndReturn(objVar, castType, rhs string) string

TplSetAndReturn returns a code to write the property value on a given object.

type Relation

type Relation struct {
	Target struct {
		Name string
	}
}

Relation contains information about a "to-one" relation

type StandaloneRelation added in v0.9.0

type StandaloneRelation struct {
	Identifier
	Target struct {
		Identifier
		Name      string
		IsPointer bool
	}
	Name string
	// contains filtered or unexported fields
}

StandaloneRelation contains information about a "to-many" relation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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