Oihana PHP

DeleteAllModel

Contract for models able to delete a set of documents in one call.

A DeleteAllModel exposes a single DeleteAllModel::deleteAll() operation that removes every document matching the supplied options — or the whole collection when no filter is given. Unlike TruncateModel::truncate(), which empties the storage wholesale, deleteAll() runs an actual delete query and may therefore honour conditions and return the affected documents.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

deleteAll()  : mixed
Deletes a set of documents in the model.

Methods

deleteAll()

Deletes a set of documents in the model.

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

Operation options scoping the deletion, typically a set of conditions with their binds and an optional return clause. An empty array removes every document.

Tags
example
use oihana\models\interfaces\DeleteAllModel;

class SessionModel implements DeleteAllModel
{
    public function deleteAll( array $init = [] ) : mixed
    {
        return $this->store->removeWhere( $init[ 'conditions' ] ?? null ) ;
    }
}

$model = new SessionModel() ;

// remove every expired session
$model->deleteAll( [ 'conditions' => 'doc.expiresAt < @now', 'binds' => [ 'now' => time() ] ] ) ;
Return values
mixed

The deleted documents or an operation result, depending on the implementation (commonly an object, an array, or null).

On this page

Search results