// benchInsertVaryingLengthBuilder builds an INSERT statement with varying
// length data.
func benchInsertVaryingLengthBuilder(maxBytes, maxText int) (*dat.InsertBuilder, error) {
	var columns []string
	var values []interface{}

	if maxBytes > 0 {
		image := make([]byte, maxBytes)
		for i := 0; i < maxBytes; i++ {
			image[i] = byte(i % 256)
		}
		columns = append(columns, "image")
		values = append(values, image)
	}

	if maxText > 0 {
		var buf bytes.Buffer
		for i := 0; i < maxText; i++ {
			if i > 0 && i%1024 == 0 {
				// force escaping
				buf.WriteRune('\'')
			} else {
				buf.WriteRune('t')
			}
		}
		columns = append(columns, "name")
		values = append(values, buf.String())
	}

	builder := dat.
		NewInsertBuilder("benches").
		Columns(columns...).
		Values(values...)

	return builder, nil
}
// benchInsertBuilders builds an insert statement with
// many values.
//
// INSERT INTO(benches)
// VALUES (row0), (row1), ... (rown-1)
func benchInsertBuilder(rows int, argc int) (*dat.InsertBuilder, error) {
	if argc > 4 {
		panic("args must be <= 4")
	}

	columns := []string{"amount", "name", "n", "is_ok"}
	values := []interface{}{42.0, "foo", 42, "true"}
	builder := dat.
		NewInsertBuilder("benches").
		Whitelist(columns[0:argc]...)

	// fill image with random bytes
	maxImage := 256
	image := make([]byte, maxImage)
	for i := 0; i < maxImage; i++ {
		image[i] = byte(i % 256)
	}

	for i := 0; i < rows; i++ {
		builder.Values(values[0:argc]...)
	}
	return builder, nil
}
Beispiel #3
0
// InsertInto creates a new InsertBuilder for the given table.
func (q *Queryable) InsertInto(table string) *dat.InsertBuilder {
	b := dat.NewInsertBuilder(table)
	b.Execer = NewExecer(q.runner, b)
	return b
}