x

package
Version: v2.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BulkUpdate

func BulkUpdate(ctx context.Context, db dbq.ExecContexter, updateData map[interface{}]interface{}, opts BulkUpdateOptions) (sql.Result, error)

BulkUpdate is used to update multiple rows in a table without a transaction.

updateData's key must be the primary key's value in the table.

updateData's value is a slice containing the new values for each column. A nil value for a column is acceptable. The slice must be the same length as the number of columns being updated.

NOTE: You should perform benchmarks to determine if using a transaction and multiple single-row updates is more efficient for your use-case.

Example:

opts := x.BulkUpdateOptions{
   Table:      "tablename",
   Columns:    []string{"name", "age"},
   PrimaryKey: "id",
}

updateData := map[interface{}]interface{}{
   1: []interface{}{"rabbit", 5},
   2: []interface{}{"cat", 8},
}

x.BulkUpdate(ctx, db, updateData, opts)

Types

type BulkUpdateOptions

type BulkUpdateOptions struct {

	// Table sets the table name.
	Table string

	// Columns sets the columns that require updating.
	Columns []string

	// PrimaryKey sets the column name which is the primary key for the purposes of how
	// BulkUpdate works.
	PrimaryKey string

	// StmtSuffix appends additional sql content to the end of the generated sql statement.
	StmtSuffix string

	// DBType sets the database being used. The default is MySQL.
	DBType dbq.Database

	// RetryPolicy can be set if you want to retry the query in the event of failure.
	//
	// Example:
	//
	//  dbq.ExponentialRetryPolicy(60 * time.Second, 3)
	//
	RetryPolicy backoff.BackOff
}

BulkUpdateOptions is used to configure the BulkUpdate function.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL