...

Package bulk

import "github.com/calebthompson/bulk"
Overview
Index

Overview ▾

Constants

const MaxBindVars = 65535

type Insert

type Insert struct {
    *sql.DB
    SQL   string
    Casts []string
    // contains filtered or unexported fields
}

Insert represents a bulk insert statement. It is initialized using a *sql.DB, a SQL string, and an array of cast types for the columns in the insert statement. Any of the Casts may be an empty string (""), but the length of Casts must be equal to the number of columns being inserted. The substring "<values>" in SQL will be replaces with an expression for the values being inserted.

func NewInsert

func NewInsert(db *sql.DB, sql string, casts []string) *Insert

func (*Insert) Exec

func (s *Insert) Exec(rows [][]driver.Value) (sql.Result, error)

Exec runs the Insert statement in as many batches as required to allow Insert.DB to fill placeholder vars. The number of batches which will be run is equal to len(casts) * len(rows) / MaxBindVars + 1. It returns sql.Result and the first error, if any, which occurs will short-circuit the operation.