CRUD

The acronym CRUD stands for Create, Read, Update and Delete: those are names of main operations you will be allowed (directly or indirectly) to perform on databases that are supporting your application.

Notice that: if you only need read permissions from a database such as PostgreSQL or MySQL, you do SHOULD NOT to use an user with full access.

Create

The creation of a new document/row either starts from a CollectionInterface, such as SerializableCollection or a native PHP array.

The function that has to be called is create that also requires the name of the table/collection to be affected:

use Gishiki\Database\DatabaseManager;

$connection = DatabaseManager::retrieve('connectionName');

$idOfNewDocument = $connection->create('tbname', new SerializableCollection([
    'name'      => $name,
    'surname'   => $surname,
    'nickname'  => $nickname,
    'password'  => $hash //it is NOT good to store plain passwords
]));

Where the name of the connection is the same name in the application configuration.

Delete

To delete a restricted set of documents/rows from a table/collection you have to call, on the desired database connection the delete function.

The delete function needs the name of the table/collection to be affected and a valid instance of SelectionCriteria:

use Gishiki\Database\DatabaseManager;
use Gishiki\Database\Runtime\SelectionCriteria;
use Gishiki\Database\Runtime\FieldRelation;

$connection = DatabaseManager::retrieve('connectionName');

$connection->delete('tbname', SelectionCriteria::select([
            'nickname' => $nickname
        ])->orWhere('email', FieldRelation::EQUAL, $email)
    );

You can also delete EVERY documents/rows from a table/collection using the deleteAll function.

The delete function only needs the name of the table/collection to be affected:

use Gishiki\Database\DatabaseManager;
use Gishiki\Database\Runtime\SelectionCriteria;
use Gishiki\Database\Runtime\FieldRelation;

$connection = DatabaseManager::retrieve('connectionName');

$connection->deleteAll('tbname');

Note that: calling the delete function, passing an empty SelectionCriteria object has the same effect of calling deleteAll, however deleteAll will perform a little better!