Documentation ¶
Overview ¶
Package pbind provides means of binding protocol buffer message types to sql.Rows output.
A common design challange with Go is scanning sql.Rows results into structs. Ussualy, one would scan into the indivudual fields or local variables. But what if the the selected columns are a variable in the application? In such cases developers have to resort to reflection, an ORM based on reflection or a code generator like SQLBoiler with tons of adaptor code.
Pbind is for protocol buffer developers which like to avoid the usage of ORMs or reflection. It uses protoreflect, which uses the embedded protobuf descriptors in the generated Go code. This should give a potential performance edge over Go reflection.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Scan ¶
Scan the values from a Rows iteration into a protobuf message. The caller must call rows.Next() before each call of Scan.
Column (or alias) names are matched with the proto Message Field Names. If a column name cannot be matched to a Field Name, Scan returns an error.
All (and only) scalar Field types are supported as defined at: https://developers.google.com/protocol-buffers/docs/proto3#scalar.
Example ¶
Example to scan into the protobuf message as defined in test/pb/bind_test.proto.
// Scanning will match the probuf field names (case sensitive!). // If the column name does not match the field name, use an alias. const query = "select something as toggle, number, snumber, unumber, large, slarge, ularge, sfloat, lfloat, text, bin from table;" rows, err := db.Query(query) if err != nil { panic(err) } defer rows.Close() var msgs []*pb.Msg for rows.Next() { msg := new(pb.Msg) if err := Scan(rows, msg); err != nil { panic(err) } msgs = append(msgs, msg) }
Output:
Types ¶
This section is empty.