Documentation
¶
Index ¶
- Variables
- func Program(importPath string) (*loader.Program, error)
- type AnnotatedType
- type Field
- func (f *Field) Column() SQLColumn
- func (f *Field) Columns() []SQLColumn
- func (f *Field) IsForwardReference() bool
- func (f *Field) IsReference() bool
- func (f *Field) IsReversedReference() bool
- func (f *Field) IsSettable() bool
- func (f *Field) Name() string
- func (f *Field) RelationName() string
- func (f *Field) RelationTable() string
- func (f *Field) RelationTypes() (first, second *Type)
- func (f *Field) String() string
- type ForeignKey
- type SQLColumn
- type Type
- func (t *Type) Ext(curPkg string) string
- func (t *Type) HasOneToManyRelation() bool
- func (t *Type) ImportPath() string
- func (t *Type) Imports() []string
- func (t *Type) IsBasic() bool
- func (t *Type) LoadFields(levels int) error
- func (t *Type) NonReferences() []*Field
- func (t *Type) Package() string
- func (t *Type) ReferencedTypes() []*Type
- func (t *Type) References() []*Field
- func (t *Type) String() string
- func (t *Type) Table() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTypeNotFound is returned when the request type was not found ErrTypeNotFound = errors.New("type was not found") )
Functions ¶
Types ¶
type AnnotatedType ¶
AnnotatedType is a go type with it's usage information in a context.
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) IsForwardReference ¶
IsForwardReference returns true for a type that references another type
func (*Field) IsReference ¶
IsReference returns true of the field references another row in a table (another object)
func (*Field) IsReversedReference ¶
IsReversedReference returns true for a type that is referenced by other types
func (*Field) IsSettable ¶
IsSettable returns whether the column could be set
func (*Field) Name ¶
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 ¶
RelationName is a name for the relation given from a field tag, or according to it's name
func (*Field) RelationTable ¶
RelationTable is the name of the table that is used to store relations according to this field.
func (*Field) RelationTypes ¶
RelationTypes return the two types that are participating in a relation that is created by this field.
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 ¶
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 ¶
HasOneToManyRelation returns true if the type has a one-to-many relationship
func (*Type) ImportPath ¶
ImportPath is a path to add to the import section for this type
func (*Type) LoadFields ¶
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 ¶
NonReferences returns all non-reference fields
func (*Type) Package ¶
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 ¶
ReferencedTypes returns a list of all referenced types from this type
func (*Type) References ¶
References returns all reference fields