// Insert insert one or more beans
349802
func (session *Session) Insert(beans ...interface{}) (int64, error) {
	var affected int64
	var err error

	if session.isAutoClose {
		defer session.Close()
	}

	for _, bean := range beans {
		switch bean.(type) {
		case map[string]interface{}:
			cnt, err := session.insertMapInterface(bean.(map[string]interface{}))
			if err != nil {
				return affected, err
			}
			affected += cnt
		case []map[string]interface{}:
			s := bean.([]map[string]interface{})
			session.autoResetStatement = false
			for i := 0; i < len(s); i++ {
				cnt, err := session.insertMapInterface(s[i])
				if err != nil {
					return affected, err
				}
				affected += cnt
			}
		case map[string]string:
			cnt, err := session.insertMapString(bean.(map[string]string))
			if err != nil {
				return affected, err
			}
			affected += cnt
		case []map[string]string:
			s := bean.([]map[string]string)
			session.autoResetStatement = false
			for i := 0; i < len(s); i++ {
				cnt, err := session.insertMapString(s[i])
				if err != nil {
					return affected, err
				}
				affected += cnt
			}
		default:
			sliceValue := reflect.Indirect(reflect.ValueOf(bean))
			if sliceValue.Kind() == reflect.Slice {
				size := sliceValue.Len()
				if size > 0 {
					if session.engine.SupportInsertMany() {
						cnt, err := session.innerInsertMulti(bean)
						if err != nil {
							return affected, err
						}
						affected += cnt
					} else {
						for i := 0; i < size; i++ {
							cnt, err := session.innerInsert(sliceValue.Index(i).Interface())
							if err != nil {
								return affected, err
							}
							affected += cnt
						}
					}
				}
			} else {
				cnt, err := session.innerInsert(bean)
				if err != nil {
					return affected, err
				}
				affected += cnt
			}
		}
	}

	return affected, err
}
432537
func (col *Col) Insert(doc map[string]interface{}) (id int, err error) {
	docJS, err := json.Marshal(doc)
	if err != nil {
		return
	}
	id = rand.Int()
	partNum := id % col.db.numParts
	col.db.schemaLock.RLock()
	part := col.parts[partNum]

	// Put document data into collection
	part.DataLock.Lock()
	_, err = part.Insert(id, []byte(docJS))
	part.DataLock.Unlock()
	if err != nil {
		col.db.schemaLock.RUnlock()
		return
	}

	part.LockUpdate(id)
	// Index the document
	col.indexDoc(id, doc)
	part.UnlockUpdate(id)

	col.db.schemaLock.RUnlock()
	return
}
1277662
func (dal *DjangoAdminLog) Insert(db XODB) error {
	var err error

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

	// sql insert query, primary key provided by sequence
	const sqlstr = `INSERT INTO public.django_admin_log (` +
		`action_time, object_id, object_repr, action_flag, change_message, content_type_id, user_id` +
		`) VALUES (` +
		`$1, $2, $3, $4, $5, $6, $7` +
		`) RETURNING id`

	// run query
	XOLog(sqlstr, dal.ActionTime, dal.ObjectID, dal.ObjectRepr, dal.ActionFlag, dal.ChangeMessage, dal.ContentTypeID, dal.UserID)
	err = db.QueryRow(sqlstr, dal.ActionTime, dal.ObjectID, dal.ObjectRepr, dal.ActionFlag, dal.ChangeMessage, dal.ContentTypeID, dal.UserID).Scan(&dal.ID)
	if err != nil {
		return err
	}

	// set existence
	dal._exists = true

	return nil
}
1180263
func (b *Builder) Insert(key []byte, val uint64) error {
	// ensure items are added in lexicographic order
	if bytes.Compare(key, b.last) < 0 {
		return ErrOutOfOrder
	}
	if len(key) == 0 {
		b.len = 1
		b.unfinished.setRootOutput(val)
		return nil
	}

	prefixLen, out := b.unfinished.findCommonPrefixAndSetOutput(key, val)
	b.len++
	err := b.compileFrom(prefixLen)
	if err != nil {
		return err
	}
	b.copyLastKey(key)
	b.unfinished.addSuffix(key[prefixLen:], out)

	return nil
}
224264
func Insert(records ...interface{}) error {
	for _, rec := range records {
		if !isPtr(rec) {
			return NoPtr
		}

		if err := addNewFields(rec); err != nil {
			return err
		}

		s, err := GetSession()
		if err != nil {
			return err
		}
		defer s.Close()

		coll := GetColl(s, typeName(rec))
		err = coll.Insert(rec)
		if err != nil {
			return err
		}
	}

	return nil
}
605688
func (buf *Buffer) Insert(rs ...rune) error {
	rsLen := len(rs)
	total := buf.size + rsLen

	if total > len(buf.data) {
		buf.data = append(buf.data, make([]rune, rsLen)...)
	}

	// Shift characters to make room in the correct pos.
	if buf.size != buf.pos {
		copy(buf.data[buf.pos+rsLen:buf.size+rsLen], buf.data[buf.pos:buf.size])
	}

	for _, r := range rs {
		buf.data[buf.pos] = r
		buf.pos++
		buf.size++
	}

	return buf.Refresh()
}
588830
func (ag *AuthGroup) Insert(db XODB) error {
	var err error

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

	// sql query
	const sqlstr = `INSERT INTO django.auth_group (` +
		`name` +
		`) VALUES (` +
		`:1` +
		`) RETURNING id /*lastInsertId*/ INTO :pk`

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

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

	// set primary key and existence
	ag.ID = float64(id)
	ag._exists = true

	return nil
}
1207504
func (ag *AuthGroup) Insert(db XODB) error {
	var err error

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

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

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

	// set existence
	ag._exists = true

	return nil
}
584249
func (s *nodeStack) insert(i int, n *Node) {
	(*s) = append(*s, nil)
	copy((*s)[i+1:], (*s)[i:])
	(*s)[i] = n
}
382040
func (l *ItemList) insert(e, at *ItemElement) *ItemElement {
	n := at.next
	at.next = e
	e.prev = at
	e.next = n
	n.prev = e
	e.list = l
	l.len++
	return e
}
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
}
708701
func (s *Action) Insert(ctx context.Context, c *cli.Context) error {
	echo := c.Bool("echo")
	multiline := c.Bool("multiline")
	force := c.Bool("force")
	append := c.Bool("append")

	args, kvps := parseArgs(c)
	name := args.Get(0)
	key := args.Get(1)

	if name == "" {
		return ExitError(ctx, ExitNoName, nil, "Usage: %s insert name", s.Name)
	}

	return s.insert(ctx, c, name, key, echo, multiline, force, append, kvps)
}
489389
func (f *Filter) Insert(v []byte) {
	h := f.hash(v)
	for i := uint64(0); i < f.k; i++ {
		loc := f.location(h, i)
		f.b[loc>>3] |= 1 << (loc & 7)
	}
}
677281
func (p *PriorityQueue) Insert(v interface{}, priority float64) {
	_, ok := p.lookup[v]
	if ok {
		return
	}

	newItem := &item{
		value:    v,
		priority: priority,
	}
	heap.Push(p.itemHeap, newItem)
	p.lookup[v] = newItem
}
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
}
1349138
func (s Set) Insert(blob []byte) {
	shard := &s[ShardIndex(blob, len(s))]
	if *shard == nil {
		*shard = make(Shard)
	}
	(*shard)[string(blob)] = struct{}{}
}
385478
func Insert(table string) *InsertBuilder {
	return &InsertBuilder{
		tableName: table,
		query:     fmt.Sprintln(`INSERT INTO`, table),
		lock:      new(sync.Mutex),
	}
}