Delete records

@param array $filter

@return int Deleted records count

@throws Exception\RepositoryException
768142
public function destroyBy(array $filter = [])
    {
        try {
            return $this->query()->delete()
                ->setFilter($filter)
                ->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
546223
public static function delete(array $where): int
    {
        $self = static::getInstance();

        if (!\count($where)) {
            throw new DbException(
                "Method `Table::delete()` can't delete all records in the table `{$self->name}`,\n" .
                "please use `Db::query()` instead (of cause if you know what are you doing)"
            );
        }


        $where = static::filterColumns($where);

        if (!\count($where)) {
            throw new DbException(
                "Invalid field names of table `{$self->name}`. Please check use of `delete()` method"
            );
        }

        $table = DbProxy::quoteIdentifier($self->name);

        $sql = "DELETE FROM $table WHERE " . implode(' AND ', self::prepareStatement($where));
        return DbProxy::query($sql, array_values($where));
    }
110090
public function prune(array $filters = null)
    {
        $filters = self::checkPruneFilter($filters);

        $url = self::$base_url.'/prune?'.http_build_query(['filters' => $filters]);

        return self::$curl->post($url);
    }
832002
public function count($entityType, $filter = '')
	{
		$params = array('type_name' => $entityType);
		if (!empty($filter)) {
			$params['filter'] = $filter;
		}
		return $this->post('entity.count', $params);
	}
657855
protected function applySimpleFilter(Filter $filter)
    {
        $value = (array) $filter->getValue();
        if (count($value) > 1) {
            $this->query->whereIn($filter->getField(), $value);
        } else {
            $this->query->where($filter->getField(),
                $filter->getOperator(), $value[0]);
        }
    }
1293340
public function deleteMany(array $filter, array $options = [])
    {
        $this->writeModels[] = [BulkWrite::DELETE_MANY => [$filter, $options]];

        return $this;
    }
886543
public static function count($filter = []): int
    {
        /* @var $class LightModel */
        $className = get_called_class();
        $class = new $className;
        $tableKey = $class->getKeyName();

        $sql = 'SELECT COUNT(' . $tableKey . ') FROM ' . $class->getTableName() . ' WHERE 1=1';
        $params = self::handleFilter($sql, $filter, $class);

        $query = DB::getConnection()->prepare($sql);
        $query->execute($params);

        return (int) $query->fetchColumn(0);
    }
289872
public function removeFilter($filters) {
        foreach ((array) $filters as $filter) {
            unset($this->_filters[$filter]);

            foreach ($this->_filterMap as $tag => $f) {
                if ($f === $filter) {
                    unset($this->_filterMap[$tag]);
                }
            }
        }

        return $this;
    }
786550
public function removeFilter($filter) {
		foreach ($this->filters as $key => $value) {
			if ($value['filter'] == $filter) {
				unset($this->filters[$key]);
			}
		}

		return $this;
	}
919629
public function updateBy(Entity $entity, array $filter = [])
    {
        if (!$entity->getValidator()->validate()) {
            throw new Exception\ValidatorException($entity->getValidator());
        }

        try {
            return $this->query()->update($entity->getData())
                ->setFilter($filter)
                ->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
682300
public function deleteMany($filter, $options = [])
    {
        $filter = $this->castQuery($filter);
        $result = $this->collection->deleteMany($filter, $options);

        if ($result->isAcknowledged()) {
            return true;
        } else {
            return false;
        }
    }
23507
public function count(array $filter = [], array $options = [])
    {
        $cursor = $this->executeCommand(
            ['count' => $this->collectionName, 'query' => (object) $filter],
            $options
        );

        $result = $cursor->current();
        if (!isset($result['n'])) {
            throw new UnexpectedResultException('Command "count" did not return expected "n" field.');
        }

        return (int) $result['n'];
    }
1336107
public function removeFilter(FilterInterface $filter)
    {

        $this->filters = array_filter($this->filters, function (FilterInterface $f) use ($filter) {

            return $f !== $filter;
        });

        return $this;
    }
935180
public function delete($collection = '')
	{
		if (empty($collection))
		{
			throw new \Mongo_DbException("No Mongo collection selected to delete from");
		}

		try
		{
			if ($this->profiling)
			{
				$query = json_encode(array(
				'type'			=> 'delete',
				'collection'	=> $collection,
				'where'			=> $this->wheres,
				));

				$benchmark = \Profiler::start((string) $this->db, $query);
			}

			$this->db->{$collection}->remove($this->wheres, array('fsync' => true, 'justOne' => true));

			if (isset($benchmark))
			{
				\Profiler::stop($benchmark);
			}

			$this->_clear();
			return true;
		}
		catch (\MongoCursorException $e)
		{
			throw new \Mongo_DbException("Delete of data into MongoDB failed: {$e->getMessage()}", $e->getCode());
		}
	}
166646
public function delete($filter, array $options = [])
    {
        $this->ensureAllowedMethodCall(__METHOD__);

        if (isset($options['collation']) && !$this->server->supportsCollation()) {
            throw new UnsupportedException(
                'Option "collation" is not supported by the server.'
            );
        }

        if (null !== $this->listener) {
            $this->listener->beforeDelete($filter, $options);
        }

        $this->getWrappedBulk()->delete($filter, $options);
        $this->currentPosition += 1;
    }
523688
public function filter($filter)
    {
        if (is_array($filter)) {
            $filter = new Filter($filter);
        }
        $this->filter = $filter;
        return $this;
    }
462318
public static function getCustomersCount($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCount('/customers/count' . $filter->toQuery());
    }