Пример #1
0
// QueryResultToProto3 converts an internal QueryResult to the proto3 version
func QueryResultToProto3(qr *QueryResult) *pbq.QueryResult {
	result := &pbq.QueryResult{
		RowsAffected: qr.RowsAffected,
		InsertId:     qr.InsertId,
	}

	if len(qr.Fields) > 0 {
		result.Fields = make([]*pbq.Field, len(qr.Fields))
		for i, f := range qr.Fields {
			result.Fields[i] = &pbq.Field{
				Name:  f.Name,
				Type:  pbq.Field_Type(f.Type),
				Flags: int64(f.Flags),
			}
		}
	}

	if len(qr.Rows) > 0 {
		result.Rows = make([]*pbq.Row, len(qr.Rows))
		for i, r := range qr.Rows {
			result.Rows[i] = &pbq.Row{
				Values: make([][]byte, len(r)),
			}
			for j, c := range r {
				result.Rows[i].Values[j] = c.Raw()
			}
		}
	}

	return result
}
Пример #2
0
// FieldsToProto3 converts an internal []Field to the proto3 version
func FieldsToProto3(f []Field) []*pbq.Field {
	if len(f) == 0 {
		return nil
	}

	result := make([]*pbq.Field, len(f))
	for i, f := range f {
		result[i] = &pbq.Field{
			Name:  f.Name,
			Type:  pbq.Field_Type(f.Type),
			Flags: int64(f.Flags),
		}
	}
	return result
}