Performs an insert command for multiple documents. Returns the number of modified documents
@param array $docs an associative array with document IDs as keys and document contents as values
@return int
481497
public function insertMultiple($docs) {
		$request = new CPS_InsertRequest($docs);
		$this->_lastResponse = $this->_connection->sendRequest($request);
		return count($this->_lastResponse->getModifiedIds());
	}
436420
public function insertGetId(array $values): int {
    $this->coerceDataTypesToDatabase($values);
    return $this->builder->insertGetId($values);
  }
524003
public function put(array $arr_docs)
    {
        $obj_request = new IndexDocumentRequest();
        $obj_params = $this->prepareRequestParams($obj_request);

        // Other index specs: consistency, mode, name, namespace, source, version
        $obj_mapper = new Mapper();
        foreach($arr_docs as $obj_doc) {
            $obj_mapper->toGoogle($obj_doc, $obj_params->addDocument());
        }
        $this->execute('IndexDocument', $obj_request, new IndexDocumentResponse());
    }
99523
public function insert(array $values) : int
    {
        $fields = $this->fields;
        array_shift($fields);

        $sql = 'INSERT INTO `' . $this->table . '` (' . implode(', ', $fields) . ') VALUES (:' . implode(', :', $fields) . ')';
        $query = $this->pdo->prepare($sql);
        foreach ($values as $key => &$value) {
            $query->bindParam(':' . $fields[$key], $value);
        }
        $query->execute();

        return $this->pdo->lastInsertId();
    }
774308
private function executeReorders($documents)
    {
        foreach ($documents as $oid => $list) {
            if (!$this->contains($oid)) {
                continue;
            }
            foreach ($list as $value) {
                list($parent, $src, $target, $before) = $value;
                $parentNode = $this->session->getNode($this->getDocumentId($parent));

                // check for src and target ...
                $dest = $target;
                if ($parentNode->hasNode($src) && $parentNode->hasNode($target)) {
                    // there is no orderAfter, so we need to find the child after target to use it in orderBefore
                    if (!$before) {
                        $dest = null;
                        $found = false;
                        foreach ($parentNode->getNodes() as $name => $child) {
                            if ($name === $target) {
                                $found = true;
                            } elseif ($found) {
                                $dest = $name;
                                break;
                            }
                        }
                    }

                    $parentNode->orderBefore($src, $dest);
                    $class = $this->dm->getClassMetadata(get_class($parent));
                    foreach ($class->childrenMappings as $fieldName) {
                        if ($parent instanceof Proxy && $parent->__isInitialized()) {
                            $children = $class->reflFields[$fieldName]->getValue($parent);
                            $children->refresh();
                        }
                    }
                }
            }
        }
    }
368885
public function insert(array &$doc)
    {
        if (isset($doc['_id'])) {
            $clone = $doc;
            unset($clone['_id']);

            $response = $this->client->request('PUT', "/{$this->name}/{$doc['_id']}", [
                'body'    => JSONEncoder::encode($clone),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        } else {
            $response = $this->client->request('POST', "/{$this->name}/", [
                'body'    => JSONEncoder::encode($doc),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        }

        if (201 !== $response->getStatusCode()) {
            throw new Exception('Unable to save document');
        }

        $value = JSONEncoder::decode((string) $response->getBody());

        $doc['_id'] = $value['id'];
        $doc['_rev'] = $value['rev'];
    }
96535
private function executeRemovals($documents)
    {
        foreach ($documents as $oid => $document) {
            if (empty($this->documentIds[$oid])) {
                continue;
            }

            $class = $this->dm->getClassMetadata(get_class($document));
            $id = $this->getDocumentId($document);

            try {
                $node = $this->session->getNode($id);
                $this->doRemoveAllTranslations($document, $class);
                $node->remove();
            } catch (PathNotFoundException $e) {
            }

            $this->unregisterDocument($document);
            $this->purgeChildren($document);

            if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::postRemove)) {
                $this->eventListenersInvoker->invoke(
                    $class,
                    Event::postRemove,
                    $document,
                    new LifecycleEventArgs($document, $this->dm),
                    $invoke
                );
            }
        }
    }
119366
public function save(&$document) {

        return isset($document['_id']) ? $this->update(array('_id' => $document['_id']), $document) : $this->insert($document);
    }
282449
protected function docToArray(array $doc)
    {
        $values = [];

        foreach ($doc as $key => $value) {

            if ( ! is_array($value)) {
                $values[$key][] = $value;

                continue;
            }

            $values[$key] = $value;
        }

        return $values;
    }
1259248
protected function sqlinsert(array $fields, array $nums = null, array $bools = null) {
		$db = $this->db;

		$nums != null or $nums = [];
		$bools != null or $bools = [];

		$keys = array_keys($fields);
		$strs = array_diff($keys, $bools, $nums);

		$key_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
			return "`$val`";
		});

		$value_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
			return ":$val ";
		});

		$db->prepare
			(
				"	INSERT INTO `[table]`
						   ($key_fields)
					VALUES ($value_fields)
				",
				[ 'table' => $this->constants()['table'] ]
			)
			->strs($fields, $strs)
			->bools($fields, $bools)
			->nums($fields, $nums)
			->execute();

		return $db->lastInsertId();
	}
59479
private function executeUpdates($documents, $dispatchEvents = true)
    {
        foreach ($documents as $oid => $document) {
            if (!$this->contains($oid)) {
                continue;
            }

            $class = $this->dm->getClassMetadata(get_class($document));
            $node = $this->session->getNode($this->getDocumentId($document));

            if ($this->writeMetadata) {
                $this->documentClassMapper->writeMetadata($this->dm, $node, $class->name);
            }

            if ($dispatchEvents) {
                if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::preUpdate)) {
                    $this->eventListenersInvoker->invoke(
                        $class,
                        Event::preUpdate,
                        $document,
                        new PreUpdateEventArgs($document, $this->dm, $this->documentChangesets[$oid]),
                        $invoke
                    );
                    $this->changesetComputed = array_diff($this->changesetComputed, [$oid]);
                    $this->computeChangeSet($class, $document);
                }
            }

            $fields = $this->documentChangesets[$oid]['fields'] ?? [];
            foreach ($fields as $fieldName => $data) {
                $fieldValue = $data[1];

                // PHPCR does not validate nullable unless we would start to
                // generate custom node types, which we at the moment don't.
                // the ORM can delegate this validation to the relational database
                // that is using a strict schema.
                // do this after the preUpdate events to give listener a last
                // chance to provide values
                if (null === $fieldValue
                    && in_array($fieldName, $class->fieldMappings) // only care about non-virtual fields
                    && !$class->isNullable($fieldName)
                    && !$this->isAutocreatedProperty($class, $fieldName)
                ) {
                    throw new PHPCRException(sprintf('Field "%s" of class "%s" is not nullable', $fieldName, $class->name));
                }

                // Ignore translatable fields (they will be persisted by the translation strategy)
                if (in_array($fieldName, $class->translatableFields)) {
                    continue;
                }

                $mapping = $class->mappings[$fieldName];
                if (in_array($fieldName, $class->fieldMappings)) {
                    $type = PropertyType::valueFromName($mapping['type']);
                    if ($mapping['multivalue']) {
                        $value = empty($fieldValue) ? null : ($fieldValue instanceof Collection ? $fieldValue->toArray() : $fieldValue);
                        if ($value && isset($mapping['assoc'])) {
                            $value = $this->processAssoc($node, $mapping, $value);
                        }
                    } else {
                        $value = $fieldValue;
                    }
                    $node->setProperty($mapping['property'], $value, $type);
                } elseif ($mapping['type'] === $class::MANY_TO_ONE
                    || $mapping['type'] === $class::MANY_TO_MANY
                ) {
                    if (!$this->writeMetadata) {
                        continue;
                    }
                    if ($node->hasProperty($mapping['property']) && is_null($fieldValue)) {
                        $node->getProperty($mapping['property'])->remove();
                        if (isset($mapping['assoc'])) {
                            $this->removeAssoc($node, $mapping);
                        }
                        continue;
                    }

                    switch ($mapping['strategy']) {
                        case 'hard':
                            $strategy = PropertyType::REFERENCE;
                            break;
                        case 'path':
                            $strategy = PropertyType::PATH;
                            break;
                        default:
                            $strategy = PropertyType::WEAKREFERENCE;
                            break;
                    }

                    if ($mapping['type'] === $class::MANY_TO_MANY) {
                        if (isset($fieldValue)) {
                            $refNodesIds = [];
                            foreach ($fieldValue as $fv) {
                                if ($fv === null) {
                                    continue;
                                }

                                $associatedNode = $this->session->getNode($this->getDocumentId($fv));
                                if ($strategy === PropertyType::PATH) {
                                    $refNodesIds[] = $associatedNode->getPath();
                                } else {
                                    $refClass = $this->dm->getClassMetadata(get_class($fv));
                                    $this->setMixins($refClass, $associatedNode, $fv);
                                    if (!$associatedNode->isNodeType('mix:referenceable')) {
                                        throw new PHPCRException(sprintf('Referenced document %s is not referenceable. Use referenceable=true in Document annotation: '.self::objToStr($document, $this->dm), ClassUtils::getClass($fv)));
                                    }
                                    $refNodesIds[] = $associatedNode->getIdentifier();
                                }
                            }

                            $refNodesIds = empty($refNodesIds) ? null : $refNodesIds;
                            $node->setProperty($mapping['property'], $refNodesIds, $strategy);
                        }
                    } elseif ($mapping['type'] === $class::MANY_TO_ONE) {
                        if (isset($fieldValue)) {
                            $associatedNode = $this->session->getNode($this->getDocumentId($fieldValue));

                            if ($strategy === PropertyType::PATH) {
                                $node->setProperty($fieldName, $associatedNode->getPath(), $strategy);
                            } else {
                                $refClass = $this->dm->getClassMetadata(get_class($fieldValue));
                                $this->setMixins($refClass, $associatedNode, $document);
                                if (!$associatedNode->isNodeType('mix:referenceable')) {
                                    throw new PHPCRException(sprintf('Referenced document %s is not referenceable. Use referenceable=true in Document annotation: '.self::objToStr($document, $this->dm), ClassUtils::getClass($fieldValue)));
                                }
                                $node->setProperty($mapping['property'], $associatedNode->getIdentifier(), $strategy);
                            }
                        }
                    }
                } elseif ('referrers' === $mapping['type']) {
                    if (isset($fieldValue)) {

                        /*
                         * each document in referrers field is supposed to
                         * reference this document, so we have to update its
                         * referencing property to contain the uuid of this
                         * document
                         */
                        foreach ($fieldValue as $fv) {
                            if ($fv === null) {
                                continue;
                            }

                            if (!$fv instanceof $mapping['referringDocument']) {
                                throw new PHPCRException(sprintf('%s is not an instance of %s for document %s field %s', self::objToStr($fv, $this->dm), $mapping['referencedBy'], self::objToStr($document, $this->dm), $mapping['fieldName']));
                            }

                            $referencingNode = $this->session->getNode($this->getDocumentId($fv));
                            $referencingMeta = $this->dm->getClassMetadata($mapping['referringDocument']);
                            $referencingField = $referencingMeta->getAssociation($mapping['referencedBy']);

                            $uuid = $node->getIdentifier();
                            $strategy = $referencingField['strategy'] == 'weak' ? PropertyType::WEAKREFERENCE : PropertyType::REFERENCE;
                            switch ($referencingField['type']) {
                                case ClassMetadata::MANY_TO_ONE:
                                    $ref = $referencingMeta->getFieldValue($fv, $referencingField['fieldName']);
                                    if ($ref !== null && $ref !== $document) {
                                        throw new PHPCRException(sprintf('Conflicting settings for referrer and reference: Document %s field %s points to %s but document %s has set first document as referrer on field %s', self::objToStr($fv, $this->dm), $referencingField['fieldName'], self::objToStr($ref, $this->dm), self::objToStr($document, $this->dm), $mapping['fieldName']));
                                    }
                                    // update the referencing document field to point to this document
                                    $referencingMeta->setFieldValue($fv, $referencingField['fieldName'], $document);
                                    // and make sure the reference is not deleted in this change because the field could be null
                                    unset($this->documentChangesets[spl_object_hash($fv)]['fields'][$referencingField['fieldName']]);
                                    // store the change in PHPCR
                                    $referencingNode->setProperty($referencingField['property'], $uuid, $strategy);
                                    break;
                                case ClassMetadata::MANY_TO_MANY:
                                    /** @var $collection ReferenceManyCollection */
                                    $collection = $referencingMeta->getFieldValue($fv, $referencingField['fieldName']);
                                    if ($collection instanceof PersistentCollection && $collection->isDirty()) {
                                        throw new PHPCRException(sprintf('You may not modify the reference and referrer collections of interlinked documents as this is ambiguous. Reference %s on document %s and referrers %s on document %s are both modified', self::objToStr($fv, $this->dm), $referencingField['fieldName'], self::objToStr($document, $this->dm), $mapping['fieldName']));
                                    }
                                    if ($collection) {
                                        // make sure the reference is not deleted in this change because the field could be null
                                        unset($this->documentChangesets[spl_object_hash($fv)]['fields'][$referencingField['fieldName']]);
                                    } else {
                                        $collection = new ReferenceManyCollection($this->dm, $fv, $referencingField['property'], [$node], $class->name, null, $this->getReferenceManyCollectionTypeFromMetadata($mapping));
                                        $referencingMeta->setFieldValue($fv, $referencingField['fieldName'], $collection);
                                    }

                                    if ($referencingNode->hasProperty($referencingField['property'])) {
                                        if (!in_array($uuid, $referencingNode->getProperty($referencingField['property'])->getString())) {
                                            if (!$collection instanceof PersistentCollection || !$collection->isDirty()) {
                                                // update the reference collection: add us to it
                                                $collection->add($document);
                                            }
                                            // store the change in PHPCR
                                            $referencingNode->getProperty($referencingField['property'])->addValue($uuid); // property should be correct type already
                                        }
                                    } else {
                                        // store the change in PHPCR
                                        $referencingNode->setProperty($referencingField['property'], [$uuid], $strategy);
                                    }

                                    // avoid confusion later, this change to the reference collection is already saved
                                    $collection->setDirty(false);
                                    break;
                                default:
                                    // in class metadata we only did a santiy check but not look at the actual mapping
                                    throw new MappingException(sprintf('Field "%s" of document "%s" is not a reference field. Error in referrer annotation: '.self::objToStr($document, $this->dm), $mapping['referencedBy'], ClassUtils::getClass($fv)));
                            }
                        }
                    }
                } elseif ('child' === $mapping['type']) {
                    if ($fieldValue === null && $node->hasNode($mapping['nodeName'])) {
                        $child = $node->getNode($mapping['nodeName']);
                        $childDocument = $this->getOrCreateDocument(null, $child);
                        $this->purgeChildren($childDocument);
                        $child->remove();
                    }
                }
            }

            if (!empty($this->documentChangesets[$oid]['reorderings'])) {
                foreach ($this->documentChangesets[$oid]['reorderings'] as $reorderings) {
                    foreach ($reorderings as $srcChildRelPath => $destChildRelPath) {
                        $node->orderBefore($srcChildRelPath, $destChildRelPath);
                    }
                }
            }

            $this->doSaveTranslation($document, $node, $class);

            if ($dispatchEvents) {
                if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::postUpdate)) {
                    $this->eventListenersInvoker->invoke(
                        $class,
                        Event::postUpdate,
                        $document,
                        new LifecycleEventArgs($document, $this->dm),
                        $invoke
                    );
                }
            }
        }
    }
110412
public function insert($params)
    {
        if (is_array($params)) {
            $count_rows = count($params['columns']);
            $increment = 1;
            foreach ($params['columns'] as $keys => $value) {
                for ($i = 1; $i <= $count_rows; $i++) {
                    $data[$keys] = $value;
                }
            }
            foreach ($data as $keys => $values) {
                if ($increment == $count_rows) {
                    $columns[] = "{$keys} = '{$values}'";
                } else {
                    $columns[] = "{$keys} = '{$values}'";
                }
                $increment++;
            }
            $columns = implode(' , ', $columns);
            $query = "INSERT INTO `{$params['table']}`SET {$columns}";
            if (isset($params['debug']) and strtolower($params['debug']) === 'on') {
                var_dump($query);
            }

            return $query;
        } else {
            return false;
        }
    }
620325
public function inserts(array $kvs): int
    {
        $params = [];
        foreach ($kvs as $key => $val) {
            $params[] = $val; //分数(值)
            $params[] = $key; //元素(键)
        }
        return $this->handle->zAdd($this->name, ...$params);
    }
137592
public function insertOne($document, $options = [])
    {
        $query = new InsertOne($this->documentManager, $this, $document, $options);
        if (isset($options['getQuery']) && $options['getQuery']) {
            return $query;
        } else {
            return $query->execute();
        }
    }
1182519
public function indexMultiple(array $documents)
    {
        $index = $this->client->getIndex($this->indexName);

        foreach ($documents as $document) {
            $this->indexDocument($document, $index);
        }

        $index->refresh();
    }
208643
public function detectNamespacesFromDocument( $doc )
	{
		$namespaces	= self::getNamespacesFromDocument( $element );
		$this->namespaces	= array_merge( $this->namespaces, $namespaces );
		return count( $namespaces );
	}
187017
public function add($documents)
    {

        $pendingRemove = $this->getRemove();
        if ($this->getRemove()) {
            if ($this->all()) {
                throw new \RuntimeException('Adding to group with pending remove is not permitted');
            } else {
                $this->clearAdd();
                $this->clearRemove();
                $this->saved = array();
            }
        }
        if (!is_array($documents)) {
            $documents = array($documents);
        }

        $add =& $this->getArchive()->getByRef('add', array());
        foreach ($documents as $document) {
            $add[] = $document;
        }
    }