func (client *client) StreamKeyRange(ctx context.Context, position string, keyspaceIdType key.KeyspaceIdType, keyRange *pbt.KeyRange, charset *mproto.Charset) (chan *proto.BinlogTransaction, binlogplayer.ErrFunc, error) { response := make(chan *proto.BinlogTransaction, 10) query := &pb.StreamKeyRangeRequest{ Position: position, KeyspaceIdType: key.KeyspaceIdTypeToProto(keyspaceIdType), KeyRange: keyRange, Charset: mproto.CharsetToProto(charset), } stream, err := client.c.StreamKeyRange(ctx, query) if err != nil { return nil, nil, err } var finalErr error go func() { for { r, err := stream.Recv() if err != nil { if err != io.EOF { finalErr = err } close(response) return } response <- proto.ProtoToBinlogTransaction(r.BinlogTransaction) } }() return response, func() error { return finalErr }, nil }
// StatementToProto converts a Statement to a proto3 func StatementToProto(s *Statement) *pb.BinlogTransaction_Statement { return &pb.BinlogTransaction_Statement{ Category: pb.BinlogTransaction_Statement_Category(s.Category), Charset: mproto.CharsetToProto(s.Charset), Sql: s.Sql, } }
func (client *client) StreamTables(ctx context.Context, position string, tables []string, charset *mproto.Charset) (chan *proto.BinlogTransaction, binlogplayer.ErrFunc, error) { response := make(chan *proto.BinlogTransaction, 10) query := &pb.StreamTablesRequest{ Position: position, Tables: tables, Charset: mproto.CharsetToProto(charset), } stream, err := client.c.StreamTables(ctx, query) if err != nil { return nil, nil, err } var finalErr error go func() { for { r, err := stream.Recv() if err != nil { if err != io.EOF { finalErr = err } close(response) return } response <- proto.ProtoToBinlogTransaction(r.BinlogTransaction) } }() return response, func() error { return finalErr }, nil }
func (client *client) StreamTables(req *proto.TablesRequest, responseChan chan *proto.BinlogTransaction) binlogplayer.BinlogPlayerResponse { query := &pb.StreamTablesRequest{ Position: myproto.ReplicationPositionToProto(req.Position), Tables: req.Tables, Charset: mproto.CharsetToProto(req.Charset), } response := &response{} stream, err := client.c.StreamTables(client.ctx, query) if err != nil { response.err = err close(responseChan) return response } go func() { for { r, err := stream.Recv() if err != nil { if err != io.EOF { response.err = err } close(responseChan) return } responseChan <- proto.ProtoToBinlogTransaction(r.BinlogTransaction) } }() return response }