Example #1
0
// Next implements plan.Plan Next interface.
func (r *ExplainDefaultPlan) Next(ctx context.Context) (row *plan.Row, err error) {
	if r.lines == nil {
		var buf bytes.Buffer
		w := format.IndentFormatter(&buf, "│   ")
		r.S.Explain(ctx, w)
		r.lines = strings.Split(string(buf.Bytes()), "\n")
	}
	if r.cursor == len(r.lines)-1 {
		return
	}
	row = &plan.Row{
		Data: []interface{}{r.lines[r.cursor]},
	}
	r.cursor++
	return
}
Example #2
0
// Do returns explain result lines.
func (r *ExplainDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error {
	var buf bytes.Buffer
	switch x := r.S.(type) {
	default:
		w := format.IndentFormatter(&buf, "│   ")
		x.Explain(ctx, w)
	}

	a := bytes.Split(buf.Bytes(), []byte{'\n'})
	for _, v := range a[:len(a)-1] {
		if more, err := f(nil, []interface{}{string(v)}); !more || err != nil {
			return err
		}
	}
	return nil
}