Documentation
¶
Index ¶
- Constants
- Variables
- func PrepareQuery(dialect string, rawSql []byte) (string, []interface{}, error)
- func RegisterEnums(enums map[string]map[string]int32)
- type Mapper
- func (m *Mapper) GetValues(rows *db.Rows, respMap *ResponseMapping) error
- func (m *Mapper) Log()
- func (m *Mapper) MapResponse(respMap *ResponseMapping) error
- func (m *Mapper) MapRow(rowValues []interface{}, sqlMap *SqlMap, sqlMapVals *SqlMapVals, ...)
- func (m *Mapper) NewResponseMapping() *ResponseMapping
- type ProtoField
- type ResponseMapping
- type SqlMap
- type SqlMapVals
- type Value
Constants ¶
const ( TopLevelElement mapType = iota Association Collection )
Map can either be, a top level element (proto response) Association, (nested field) or Collection, (repeated nested field)
Variables ¶
var (
EnumVals map[string]map[string]int32
)
Functions ¶
func RegisterEnums ¶
Types ¶
type Mapper ¶
type Mapper struct {
SqlMap *SqlMap //Mapping of top level element, proto response message
Name string //Name of the corresponding RPC
Logs map[string]bool
Error error
// contains filtered or unexported fields
}
Representation of SQL response mapping to a proto response message protoc-gen-map generates service server methods which implement interfaces generated by protoc-gen-go each RPC and therefore SQL has corresponding Mapper
func New ¶
Generates mapper instance based on proto response type and response of sql query This is done once after the first response is retrieved
func (*Mapper) GetValues ¶
func (m *Mapper) GetValues(rows *db.Rows, respMap *ResponseMapping) error
Retrieves all values from the query
func (*Mapper) Log ¶
func (m *Mapper) Log()
If non-breaking issues are found while mapping, this function prints them
func (*Mapper) MapResponse ¶
func (m *Mapper) MapResponse(respMap *ResponseMapping) error
Begin mapping the proto response This is method is called for SQL query response
func (*Mapper) MapRow ¶
func (m *Mapper) MapRow(rowValues []interface{}, sqlMap *SqlMap, sqlMapVals *SqlMapVals, protoMsg interface{}, uniqueId string)
Map a single row of the sql query This function starts with the top level element as input parameter, and is called recursively for each Association and Collection on the same row
func (*Mapper) NewResponseMapping ¶
func (m *Mapper) NewResponseMapping() *ResponseMapping
Generates Response Mapping, an object which stores mapped SQL response values
type ProtoField ¶
type ProtoField struct {
// contains filtered or unexported fields
}
ProtoField represents one field in a proto struct generated by protoc-gen-go used to keep track of its location in the parent struct
type ResponseMapping ¶
type ResponseMapping struct {
// slice of Top Level Elements, pointers to response messages
Responses []interface{}
// contains filtered or unexported fields
}
Each RPC call generates ResponseMapping, this is responsible for storing data in structure matching the proto response
type SqlMap ¶
type SqlMap struct {
Name mapName // Name of the corresponging proto message
MapType mapType //
ProtoStruct reflect.Type // type of the corresponging proto message
// ProtoStruct for Collections are slices of pointers,
// if the SqlMap Type is a Collection, this field is the pointer of the underlyiogn struct
// For top level element and association types, this field is nil
ProtoSliceElem reflect.Type
// For collections and association, this the i in reflect.Value.Field(i) where i is the ith field of the SqlMap
// which corresponds to the Proto Message which holds this association or collection.
ParentFieldId int
// Column correspond to proto message field names that match sql columns
Columns map[columnName]*ProtoField
// Columns of the SQL response which are present in this proto message
PresentColumns []string
// and those columns' values
ProtoValues []interface{}
// Associations are has-one relationships which correspond to nested proto messages
Associations map[mapName]*SqlMap
//Collections are has-many relationships which correspond to nested and repeated proto messages
Collections map[mapName]*SqlMap
Error error // breaking issue
Logs []string // non-breaking issue
}
SqlMap stores types of proto messages and their corresponding column name if the proto message has repeated and/or nested fields, they are recursively stores in Associations and Collections
type SqlMapVals ¶
type SqlMapVals struct {
// Columns values of the SQL response which are present in this proto message
// this field contained currently analysed values
ProtoValues []interface{}
// If all current ProtoValues are nil, isNil is set true and mapping of this element is omitted
IsNill bool
// Protoc-gen-map uses all present columns in a particular message to generate a unique id,
// if successive rows have the same id, it identifies the same element
// always include a uniquely identifiable column in your query
//
// interface{} in this map are pointers to response proto messages
UniqueIds map[string]interface{}
// Associations are has-one relationships which correspond to nested proto messages
Associations map[mapName]*SqlMapVals
//Collections are has-many relationships which correspond to nested and repeated proto messages
Collections map[mapName]*SqlMapVals
}
SQL Values are values returned from the SQL query which belong to a particular proto message. Pointers to those messages are stored in UniqueIds