load

package
v0.0.0-...-7203340 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeNotFound is returned when the request type was not found
	ErrTypeNotFound = errors.New("type was not found")
)

Functions

func Program

func Program(importPath string) (*loader.Program, error)

Program loads a program into memory

Types

type AnnotatedType

type AnnotatedType struct {
	*Type
	Pointer bool
	Slice   bool
}

AnnotatedType is a go type with it's usage information in a context.

func New

func New(fullName string) (*AnnotatedType, error)

New loads a AnnotatedType

func (*AnnotatedType) Ext

func (t *AnnotatedType) Ext(curPkg string) string

Ext return the type representation depending on the given package, if it is the same package as the type's, it will return only it's name. Otherwise, it will return the full "package.Name" semantic

func (*AnnotatedType) String

func (t *AnnotatedType) String() string

type Field

type Field struct {
	ParentType *Type
	// Type is the type of the field
	Type AnnotatedType
	// AccessName is the name of the field from the root struct
	// so if a field is embedded, StructA->StructB->Field, the field AccessName, from StructA
	// will be StructB.Field
	AccessName string
	// Embedded means that the field is embedded in a struct
	Embedded bool
	// CustomType can be defined to a column
	CustomType *sqltypes.Type
	// PrimaryKeys defines a column as a table's primary key
	PrimaryKey bool
	// NotNull defines that this column value can't be null
	NotNull bool
	// Null defines that this column value can be null
	Null bool
	// AutoIncrement defines this column as auto-increment column
	AutoIncrement bool
	// Unique defines that 2 rows can't have the same value of this column
	Unique bool
	// Default sets a default value for this column
	Default string
	// RelationField is to used when type A has a one-to-many relationship
	// to type B, and type B has more than one fields that reference type A.
	// in this case, the one-to-many field in A, for example 'Bs []B' should add
	// a tag with the name of the field in B that referencing it. So if type
	// B hash 'A1, A2 A', type B should add tag `sql:"relation field:A1"`.
	RelationField string
	// CustomRelationName is used to define a many-to-many relations with matching fields
	// in the related types.
	// If a file `Bs []B` in type A should be relation to field `As []A` in type B,
	// a common `relation name` tag could be given to those two fields, and a many
	// to many relation between those fields will be created.
	CustomRelationName string
}

Field is a struct that represents type's field

func (*Field) Column

func (f *Field) Column() SQLColumn

Column returns the SQL column name of a field

func (*Field) Columns

func (f *Field) Columns() []SQLColumn

Columns returns the SQL column name of a field

func (*Field) IsForwardReference

func (f *Field) IsForwardReference() bool

IsForwardReference returns true for a type that references another type

func (*Field) IsReference

func (f *Field) IsReference() bool

IsReference returns true of the field references another row in a table (another object)

func (*Field) IsReversedReference

func (f *Field) IsReversedReference() bool

IsReversedReference returns true for a type that is referenced by other types

func (*Field) IsSettable

func (f *Field) IsSettable() bool

IsSettable returns whether the column could be set

func (*Field) Name

func (f *Field) Name() string

Name is the field name If the field is embedded within another type, for example StructA->StructB->Field, to distinct between a field with name 'Field' in StructA, the name will be 'StructBField'

func (*Field) RelationName

func (f *Field) RelationName() string

RelationName is a name for the relation given from a field tag, or according to it's name

func (*Field) RelationTable

func (f *Field) RelationTable() string

RelationTable is the name of the table that is used to store relations according to this field.

func (*Field) RelationTypes

func (f *Field) RelationTypes() (first, second *Type)

RelationTypes return the two types that are participating in a relation that is created by this field.

func (*Field) String

func (f *Field) String() string

type ForeignKey

type ForeignKey struct {
	Src, Dst *Field
}

ForeignKey is a definition of how a column is a foreign key of another column in a referenced table.

type SQLColumn

type SQLColumn struct {
	// Name is the column name
	Name string
	// SetTypes is the type that is used to set a field that reference this column
	SetType *AnnotatedType
	// CustomType is a custom SQL type that can be defined by the user
	CustomType *sqltypes.Type
}

SQLColumn describe a column in an SQL table

type Type

type Type struct {
	Name string
	// Fields is the list of exported fields
	Fields      []*Field
	PrimaryKeys []*Field
	// contains filtered or unexported fields
}

Type is a type definition without it's specific usage information

func (*Type) Ext

func (t *Type) Ext(curPkg string) string

Ext return the type representation depending on the given package, if it is the same package as the type's, it will return only it's name. Otherwise, it will return the full "package.Name" semantic.

func (*Type) HasOneToManyRelation

func (t *Type) HasOneToManyRelation() bool

HasOneToManyRelation returns true if the type has a one-to-many relationship

func (*Type) ImportPath

func (t *Type) ImportPath() string

ImportPath is a path to add to the import section for this type

func (*Type) Imports

func (t *Type) Imports() []string

Imports returns a list of all imports for this type's fields

func (*Type) IsBasic

func (t *Type) IsBasic() bool

IsBasic returns try if the type is a Go basic type

func (*Type) LoadFields

func (t *Type) LoadFields(levels int) error

LoadFields iterate over the type's data structure and load all it's fields this function might recursively call to the New function

func (*Type) NonReferences

func (t *Type) NonReferences() []*Field

NonReferences returns all non-reference fields

func (*Type) Package

func (t *Type) Package() string

Package is the package name of the type for tests, type in "github.com/posener/orm/tests" has the package name: "tests"

func (*Type) ReferencedTypes

func (t *Type) ReferencedTypes() []*Type

ReferencedTypes returns a list of all referenced types from this type

func (*Type) References

func (t *Type) References() []*Field

References returns all reference fields

func (*Type) String

func (t *Type) String() string

func (*Type) Table

func (t *Type) Table() string

Table is SQL table name of a type

Jump to

Keyboard shortcuts

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