// InsertSet tests insert specifications only using Set query.
500704
func InsertSet(t *testing.T, repo grimoire.Repo) {
	user := User{}
	repo.From(users).MustSave(&user)
	now := time.Now()

	tests := []struct {
		query  grimoire.Query
		record interface{}
	}{
		{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("name", "insert set"), &User{}},
		{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("name", "insert set").Set("age", 100), &User{}},
		{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("name", "insert set").Set("age", 100).Set("note", "note"), &User{}},
		{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("note", "note"), &User{}},
		{repo.From(addresses).Set("created_at", now).Set("updated_at", now).Set("address", "address"), &Address{}},
		{repo.From(addresses).Set("created_at", now).Set("updated_at", now).Set("address", "address").Set("user_id", user.ID), &Address{}},
		{repo.From(addresses).Set("created_at", now).Set("updated_at", now).Set("user_id", user.ID), &Address{}},
	}

	for _, test := range tests {
		statement, _ := builder.Insert(test.query.Collection, test.query.Changes)

		t.Run("InsertSet|"+statement, func(t *testing.T) {
			assert.Nil(t, test.query.Insert(nil))
			assert.Nil(t, test.query.Insert(test.record))
		})
	}
}
1235245
func (c *Collection) Insert(docs ...interface{}) error {
	_, err := c.writeQuery(&insertOp{c.FullName, docs})
	return err
}
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
}
238262
func (b *BaseBuilder) Insert(table string, cols Params) *Query {
	names := make([]string, 0, len(cols))
	for name := range cols {
		names = append(names, name)
	}
	sort.Strings(names)

	params := Params{}
	columns := make([]string, 0, len(names))
	values := make([]string, 0, len(names))
	for _, name := range names {
		columns = append(columns, b.db.QuoteColumnName(name))
		value := cols[name]
		if e, ok := value.(Expression); ok {
			values = append(values, e.Build(b.db, params))
		} else {
			values = append(values, fmt.Sprintf("{:p%v}", len(params)))
			params[fmt.Sprintf("p%v", len(params))] = value
		}
	}

	var sql string
	if len(names) == 0 {
		sql = fmt.Sprintf("INSERT INTO %v DEFAULT VALUES", b.db.QuoteTableName(table))
	} else {
		sql = fmt.Sprintf("INSERT INTO %v (%v) VALUES (%v)",
			b.db.QuoteTableName(table),
			strings.Join(columns, ", "),
			strings.Join(values, ", "),
		)
	}

	return b.NewQuery(sql).Bind(params)
}
1360974
func (this *Engine) RawInsert(table string, sets map[string]interface{}) (lastId int64, err error) {
	var (
		fields string
		values string
		params []interface{}
		delim  string
	)
	for k, v := range sets {
		fields += delim + this.Quote(k)
		values += delim + "?"
		params = append(params, v)
		delim = ","
	}
	sql := `INSERT INTO ` + this.fullTableName(table) + ` (` + fields + `) VALUES (` + values + `)`
	return this.RawExec(sql, true, params...)
}
644153
func (d *Dataset) InsertValues(index int, values ...interface{}) error {
	return d.Insert(index, values[:])
}
1129824
func (s StringSet) AddSet(newValues StringSet) {
	for newValue, _ := range newValues {
		s[newValue] = struct{}{}
	}
}
1283191
func (s String) Insert(items ...string) {
	for _, item := range items {
		s[item] = struct{}{}
	}
}
1034168
func (qb *TiDBQueryBuilder) Set(kv ...string) QueryBuilder {
	qb.Tokens = append(qb.Tokens, "SET", strings.Join(kv, CommaSpace))
	return qb
}
611119
func (s Int) Insert(items ...int) {
	for _, item := range items {
		s[item] = Empty{}
	}
}
349674
func InsertType(t reflect.Type) {
	tname := nameof(t)
	if _, found := typemap[tname]; !found {
		typemap[tname] = t
	}
}
910349
func (me *TxsdStudyTypeSequenceDescriptorAllStudyTypeExistingStudyType) Set(s string) {
	(*xsdt.String)(me).Set(s)
}
1040848
func (t *Trie) Set(key []byte, value interface{}) {
	t.insert(key, value, true)
}
957435
func (me *TxsdSequencingDirectivesTypeAllSampleDemuxDirective) Set(s string) {
	(*xsdt.String)(me).Set(s)
}
1305547
func (tx *Tx) InsertContext(ctx context.Context, list ...interface{}) error {
	return insertObjects(ctx, tx.DB, tx, getInsert, list, opInsert)
}
287468
func (me *Dataset) Insert(i ...interface{}) *CrudExec {
	sql, args, err := me.ToInsertSql(i...)
	return newCrudExec(me.database, err, sql, args...)
}
211927
func InsertTx(db *sql.DB, dbTx *dbtypes.Tx, checked, updateExistingRecords bool) (uint64, error) {
	insertStatement := internal.MakeTxInsertStatement(checked, updateExistingRecords)
	var id uint64
	err := db.QueryRow(insertStatement,
		dbTx.BlockHash, dbTx.BlockHeight, dbTx.BlockTime, dbTx.Time,
		dbTx.TxType, dbTx.Version, dbTx.Tree, dbTx.TxID, dbTx.BlockIndex,
		dbTx.Locktime, dbTx.Expiry, dbTx.Size, dbTx.Spent, dbTx.Sent, dbTx.Fees,
		dbTx.NumVin, dbtypes.UInt64Array(dbTx.VinDbIds),
		dbTx.NumVout, dbtypes.UInt64Array(dbTx.VoutDbIds),
		dbTx.IsValidBlock, dbTx.IsMainchainBlock).Scan(&id)
	return id, err
}