// TxInsert is the same as Insert except it allows you specify your own transaction
325715
func (s *Store) TxInsert(tx *bolt.Tx, key, data interface{}) error {
	if !tx.Writable() {
		return bolt.ErrTxNotWritable
	}

	storer := newStorer(data)

	b, err := tx.CreateBucketIfNotExists([]byte(storer.Type()))
	if err != nil {
		return err
	}

	if _, ok := key.(sequence); ok {
		key, err = b.NextSequence()
		if err != nil {
			return err
		}
	}

	gk, err := encode(key)

	if err != nil {
		return err
	}

	if b.Get(gk) != nil {
		return ErrKeyExists
	}

	value, err := encode(data)
	if err != nil {
		return err
	}

	// insert data
	err = b.Put(gk, value)

	if err != nil {
		return err
	}

	// insert any indexes
	err = indexAdd(storer, tx, gk, data)
	if err != nil {
		return err
	}

	dataVal := reflect.Indirect(reflect.ValueOf(data))
	if !dataVal.CanSet() {
		return nil
	}
	dataType := dataVal.Type()

	for i := 0; i < dataType.NumField(); i++ {
		tf := dataType.Field(i)
		// XXX: should we require standard tag format so we can use StructTag.Lookup()?
		// XXX: should we use strings.Contains(string(tf.Tag), BoltholdKeyTag) so we don't require proper tags?
		if _, ok := tf.Tag.Lookup(BoltholdKeyTag); ok {
			fieldValue := dataVal.Field(i)
			keyValue := reflect.ValueOf(key)
			if keyValue.Type() != tf.Type {
				break
			}
			if !fieldValue.CanSet() {
				break
			}
			if !reflect.DeepEqual(fieldValue.Interface(), reflect.Zero(tf.Type).Interface()) {
				break
			}
			fieldValue.Set(keyValue)
			break
		}
	}

	return nil
}
99008
func (ref Ref) Insert(x *Term, pos int) Ref {
	if pos == len(ref) {
		return ref.Append(x)
	} else if pos > len(ref)+1 {
		panic("illegal index")
	}
	cpy := make(Ref, len(ref)+1)
	for i := 0; i < pos; i++ {
		cpy[i] = ref[i]
	}
	cpy[pos] = x
	for i := pos; i < len(ref); i++ {
		cpy[i+1] = ref[i]
	}
	return cpy
}
287468
func (me *Dataset) Insert(i ...interface{}) *CrudExec {
	sql, args, err := me.ToInsertSql(i...)
	return newCrudExec(me.database, err, sql, args...)
}
703693
func (agp *AuthGroupPermission) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if agp._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key provided by sequence
	const sqlstr = `INSERT INTO public.auth_group_permissions (` +
		`group_id, permission_id` +
		`) VALUES (` +
		`$1, $2` +
		`) RETURNING id`

	// run query
	XOLog(sqlstr, agp.GroupID, agp.PermissionID)
	err = db.QueryRow(sqlstr, agp.GroupID, agp.PermissionID).Scan(&agp.ID)
	if err != nil {
		return err
	}

	// set existence
	agp._exists = true

	return nil
}
957180
func (au *AuthUser) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if au._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key provided by sequence
	const sqlstr = `INSERT INTO public.auth_user (` +
		`password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined` +
		`) VALUES (` +
		`$1, $2, $3, $4, $5, $6, $7, $8, $9, $10` +
		`) RETURNING id`

	// run query
	XOLog(sqlstr, au.Password, au.LastLogin, au.IsSuperuser, au.Username, au.FirstName, au.LastName, au.Email, au.IsStaff, au.IsActive, au.DateJoined)
	err = db.QueryRow(sqlstr, au.Password, au.LastLogin, au.IsSuperuser, au.Username, au.FirstName, au.LastName, au.Email, au.IsStaff, au.IsActive, au.DateJoined).Scan(&au.ID)
	if err != nil {
		return err
	}

	// set existence
	au._exists = true

	return nil
}
786856
func BatchInsert(db Database, col string) DocWriter {
	if bi, ok := db.(BatchInserter); ok {
		return bi.BatchInsert(col)
	}
	return &seqInsert{db: db, col: col}
}
163675
func (m *GenericDriver) Insert(e MigrationRecord) error {

	err := transaction(m.DB, func(tx *sql.Tx) error {
		_, err := tx.Exec(m.Dialect.InsertSQL(),
			e.Version,
			e.Description,
			e.Checksum,
			e.AppliedAt.Unix(),
			e.ExecutionTime,
		)
		return err
	})

	return err
}
1128064
func (ap *AuthPermission) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if ap._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key provided by autoincrement
	const sqlstr = `INSERT INTO auth_permission (` +
		`content_type_id, codename, name` +
		`) VALUES (` +
		`?, ?, ?` +
		`)`

	// run query
	XOLog(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name)
	res, err := db.Exec(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name)
	if err != nil {
		return err
	}

	// retrieve id
	id, err := res.LastInsertId()
	if err != nil {
		return err
	}

	// set primary key and existence
	ap.ID = int(id)
	ap._exists = true

	return nil
}
907225
func (q *Query) Insert(values ...interface{}) (Result, error) {
	if q.stickyErr != nil {
		return nil, q.stickyErr
	}

	model, err := q.newModel(values...)
	if err != nil {
		return nil, err
	}

	if q.model != nil && q.model.Table().HasFlag(BeforeInsertHookFlag) {
		err = q.model.BeforeInsert(q.ctx, q.db)
		if err != nil {
			return nil, err
		}
	}

	query := newInsertQuery(q)
	res, err := q.returningQuery(model, query)
	if err != nil {
		return nil, err
	}

	if q.model != nil {
		err = q.model.AfterInsert(q.ctx, q.db)
		if err != nil {
			return nil, err
		}
	}

	return res, nil
}
1180487
func (o *querySet) PrepareInsert() (Inserter, error) {
	return newInsertSet(o.orm, o.mi)
}
1333316
func (s *TableStatistics) SetInserts(v int64) *TableStatistics {
	s.Inserts = &v
	return s
}
611119
func (s Int) Insert(items ...int) {
	for _, item := range items {
		s[item] = Empty{}
	}
}
542596
func (cr *CertificateRelease) Insert(tx *sql.Tx) error {
	query := fmt.Sprintf("INSERT INTO %ss (ski, serial, release) VALUES (?, ?, ?)", cr.Release.table())
	_, err := tx.Exec(query, cr.Certificate.SKI, cr.Certificate.Serial, cr.Release.Version)
	return err
}
508136
func NewSimpleInsert(opcode InsertOpcode, table *vindexes.Table, keyspace *vindexes.Keyspace) *Insert {
	return &Insert{
		Opcode:   opcode,
		Table:    table,
		Keyspace: keyspace,
	}
}
850941
func Tx(db *sql.DB, txFunc func(*sql.Tx) error) (err error) {
	tx, err := db.Begin()
	if err != nil {
		return
	}
	defer func() {
		if p := recover(); p != nil {
			switch p := p.(type) {
			case error:
				err = p
			default:
				err = fmt.Errorf("%s", p)
			}
		}
		if err != nil {
			tx.Rollback()
			return
		}
		err = tx.Commit()
	}()
	return txFunc(tx)
}
1014600
func (s *session) Insert(tables ...Table) error {
	for _, table := range tables {
		action, err := s.update(table, true)
		if err != nil {
			return s.catch("Insert: "+action, err)
		}
	}
	return nil
}
1016697
func (t *Transaction) Insert(list ...interface{}) error {
	return insert(t.dbmap, t, list...)
}