dbq: github.com/rocketlaunchr/dbq/v2/x Index | Files

package x

import "github.com/rocketlaunchr/dbq/v2/x"

Index

Package Files

gen_common.go

func BulkUpdate Uses

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)

type BulkUpdateOptions Uses

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.

Package x imports 10 packages (graph). Updated 2020-05-31. Refresh now. Tools for package owners.