QueryBuilder::platformInsertHandler

@param \O2System\Database\NoSql\DataStructures\QueryBuilderCache $queryBuilderCache

@return bool
162747
protected function platformInsertHandler(QueryBuilderCache $queryBuilderCache)
    {
        if ($queryBuilderCache->from) {
            return $this->conn->execute($queryBuilderCache, ['method' => 'insert']);
        }

        return false;
    }
727476
protected function load(QueryBuilder $query)
    {
        $metadata = $this->getClassMetadata();
        foreach ($metadata->getFieldMappings() as $field) {
            $fieldtype = $this->getFieldManager()->get($field['fieldtype'], $field);
            if ($fieldtype instanceof FieldTypeInterface) {
                $fieldtype->load($query, $metadata);
            }
        }
    }
16632
protected function setKeysForSaveQuery(Builder $query)
    {
        $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery());

        return $query;
    }
797186
protected function platformQueryHandler(QueryStatement &$queryStatement)
    {
        $this->parseQueryStatement($queryStatement);

        $cursor = $this->server->executeQuery($this->database . '.' . $queryStatement->getCollection(),
            new \MongoDb\Driver\Query($queryStatement->getFilter(), $queryStatement->getOptions()));

        return $cursor->toArray();
    }
202460
protected function platformUpdateBatchHandler(QueryBuilderCache $queryBuilderCache)
    {
        if ($queryBuilderCache->from) {

            // New sets document
            $collection = $queryBuilderCache->from;
            $sets = $queryBuilderCache->sets;

            // Get all old documents
            $result = $this->get();

            $newQueryBuilderCache = new QueryBuilderCache();
            $newQueryBuilderCache->store('from', $collection);

            $documentIds = [];
            foreach ($result as $document) {
                $document = $this->get()->first();
                $documentIds[] = $document->_id;
                $document = $document->getArrayCopy();
                unset($document[ '_id' ]);

                $documents[] = array_merge($document, $sets);
            }

            $newQueryBuilderCache->store('whereIn', ['_id' => $documentIds]);
            $newQueryBuilderCache->store('sets', $documents);

            return $this->conn->execute($newQueryBuilderCache, ['method' => 'update']);
        }

        return false;
    }
309289
protected function platformReplaceBatchHandler(QueryBuilderCache $queryBuilderCache)
    {
        if ($queryBuilderCache->from) {

            return $this->conn->execute($queryBuilderCache, ['method' => 'update']);
        }

        return false;
    }
782469
protected function platformDeleteHandler(QueryBuilderCache $queryBuilderCache)
    {
        if ($queryBuilderCache->from) {
            return $this->conn->execute($queryBuilderCache, ['method' => 'delete']);
        }

        return false;
    }
1046039
public function compileInsert(Builder $query, array $values)
    {
        /**
         *  Essentially we will force every insert to be treated as a batch insert which
         * simply makes creating the Cypher easier for us since we can utilize the same
         * basic routine regardless of an amount of records given to us to insert.
         *
         * We are working on getting a Cypher like this:
         * CREATE (:Wiz {fiz: 'foo', biz: 'boo'}). (:Wiz {fiz: 'morefoo', biz: 'moreboo'})
         */

        if ( ! is_array($query->from))
        {
            $query->from = array($query->from);
        }

        $label = $this->prepareLabels($query->from);

        if ( ! is_array(reset($values)))
        {
            $values = array($values);
        }

        // Prepare the values to be sent into the entities factory as
        // ['label' => ':Wiz', 'bindings' => ['fiz' => 'foo', 'biz' => 'boo']]
        $values = array_map(function($entity) use($label)
        {
            return ['label' => $label, 'bindings' => $entity];
        }, $values);
        // We need to build a list of parameter place-holders of values that are bound to the query.
        return "CREATE ". $this->prepareEntities($values);
    }
713334
public function insert(array $sets)
    {
        $this->builderCache->store('sets', $sets);

        return $this->platformInsertHandler($this->builderCache);
    }
211913
public function compileInsertGetId(Builder $query, $values, $sequence) {
    $this->beforePut($values);
    $this->remapWheres($query);
    $sql = $this->grammar->compileInsertGetId($query, $values, $sequence);

    if($this->replace_into) {
      $sql = preg_replace('/^insert into/i', 'replace into', $sql);
      $this->replace_into = false;
    }

    return $sql;
  }
559534
public static function createQueryBuilder($queryBuilder)
    {
        if ($queryBuilder instanceof ORMBuilder) {
            return new ORMQueryBuilder($queryBuilder);
        }
        if ($queryBuilder instanceof DBALBuilder) {
            return new DBALQueryBuilder($queryBuilder);
        }

        throw new QueryBuilderException(
            sprintf('Invalid parameter "queryBuilder". Use %s or %s', ORMBuilder::class, DBALBuilder::class)
        );
    }
1361676
public function setTotalCountByQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->select(sprintf('COUNT(%s)', $queryBuilder->getRootAliases()[0]))
            ->setMaxResults(1);

        return $this->setTotalCount(intval($queryBuilder->getQuery()->getSingleScalarResult()));
    }
628524
public void insert(Platform platform, Database model, int batchSize) throws SQLException
    {
        if (batchSize <= 1)
        {
            for (Iterator it = _beans.iterator(); it.hasNext();)
            {
                platform.insert(model, (DynaBean)it.next());
            }
        }
        else
        {
            for (int startIdx = 0; startIdx < _beans.size(); startIdx += batchSize)
            {
                platform.insert(model, _beans.subList(startIdx, startIdx + batchSize));
            }
        }
    }
771933
protected function platformDeleteBatchHandler(QueryBuilderCache $queryBuilderCache)
    {
        if ($queryBuilderCache->from) {
            return $this->conn->execute($queryBuilderCache, ['method' => 'delete']);
        }

        return false;
    }
774601
protected function setKeysForSaveQuery(Builder $query)
	{
		$query->where($this->morphType, $this->getAttribute($this->morphType));

		return parent::setKeysForSaveQuery($query);
	}
1125347
public function extendQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->setFirstResult($this->getFirstResult())
            ->setMaxResults($this->getLimit());

        return $this;
    }
595196
protected function performInsert(Builder $query)
    {
        if ($this->fireModelEvent('creating') === false) {
            return false;
        }

        // First we'll need to create a fresh query instance and touch the creation and
        // update timestamps on this model, which are maintained by us for developer
        // convenience. After, we will just continue saving these model instances.
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }

        // If the model has an incrementing key, we can use the "insertGetId" method on
        // the query builder, which will give us back the final inserted ID for this
        // table from the database. Not all tables have to be incrementing though.
        $attributes = $this->attributes;

        if ($this->getIncrementing()) {
            $this->insertAndSetId($query, $attributes);
        }

        // If the table is not incrementing we'll simply insert this attributes as they
        // are, as this attributes arrays must contain an "id" column already placed
        // there by the developer as the manually determined key for these models.
        else {
            if (empty($attributes)) {
                return true;
            }

            // If attributes contains binary field
            // extract binary fields to new array
            if ($this->extractBinaries($attributes)) {
                $query->getQuery()->insertLob($attributes, $this->binaryFields, $this->getKeyName());
            } else {
                $query->insert($attributes);
            }
        }

        // We will go ahead and set the exists property to true, so that it is set when
        // the created event is fired, just in case the developer tries to update it
        // during the event. This will allow them to do so and run an update here.
        $this->exists = true;

        $this->wasRecentlyCreated = true;

        $this->fireModelEvent('created', false);

        return true;
    }