Oihana PHP

TruncateModel

Contract for models able to truncate their collection.

A TruncateModel exposes a single TruncateModel::truncate() operation that empties the underlying collection, removing every document in one pass. It is the bulk, unconditional counterpart of DeleteAllModel and is typically far cheaper than deleting documents one by one.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

truncate()  : mixed
Truncates the collection and removes all documents.

Methods

truncate()

Truncates the collection and removes all documents.

public truncate([array<string|int, mixed> $init = [] ]) : mixed
Parameters
$init : array<string|int, mixed> = []

Operation options, e.g. flags forwarded to the storage engine. An empty array truncates with default settings.

Tags
example
use oihana\models\interfaces\TruncateModel;

class CacheModel implements TruncateModel
{
    public function truncate( array $init = [] ) : mixed
    {
        return $this->store->clear() ;
    }
}

$model = new CacheModel() ;
$model->truncate() ; // empties the whole collection
Return values
mixed

The truncation result, depending on the implementation (commonly a boolean, a count, or null).

On this page

Search results