Documentation
¶
Index ¶
Constants ¶
View Source
const (
CartaTagKey string = "db"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cardinality ¶
type Cardinality int
SQL Map cardinality can either be: Association: has-one relationship, must be nested structs in the response Collection: had-many relationship, repeated (slice, array) nested struct or pointer to it
const ( Unknown Cardinality = iota Association Collection )
type Field ¶
type Field struct {
Name string
Typ reflect.Type
Kind reflect.Kind
//If the field is a pointer, fields below represent the underlying type,
// these fields are here to prevent reflect.PtrTo, or reflect.elem calls when setting primatives and basic types
IsPtr bool
ElemTyp reflect.Type // if Typ is *int, elemTyp is int
ElemKind reflect.Kind // if kind is ptr and typ is *int, elem kind is int
}
type Mapper ¶
type Mapper struct {
Crd Cardinality //
IsListPtr bool // true if destination is *[], false if destination is [], used only if cardinality is a collection
// Basic mapper is used for collections where underlying type is basic (any field that is able to be set, look at isBasicType for more deatils )
// for example
// type User struct {
// UserId int
// UserAddr []sql.NullString // collection submap where mapper is basic
// UserPhone []string // also basic mapper
// UserStuff *[]*string // also basic mapper
// UserBlog []*Blog // this is NOT a basic mapper
// }
// basic can only be true if cardinality is collection
IsBasic bool
Typ reflect.Type // Underlying type to be mapped
Kind reflect.Kind // Underlying Kind to be mapped
IsTypePtr bool // is the underlying type pointed to
// present columns are columns that were found to map onto a particular fild of a struct.
// those fiels must either be basic (primative, time or sql.NullXX)
PresentColumns map[string]column
// Sorted columns are present columns in consistant order,
SortedColumnIndexes []int
// when reusing the same struct multiple times, you are able to specify the colimn prefix using parent structs
// example
// type Employee struct {
// Id int
// }
// type Manager struct {
// Employee
// Employees []Employee
// }
// the following querry would correctly map if we were mapping to *[]Manager
// "select id, employees_id from employees join managers"
// employees_ is the prefix of the parent (lower case of the parent with "_")
Fields map[fieldIndex]Field
AncestorNames []string // Field.Name of ancestors
// Nested structs which correspond to any has-one has-many relationships
// int is the ith element of this struct where the submap exists
SubMaps map[fieldIndex]*Mapper
}
Click to show internal directories.
Click to hide internal directories.
