\Gishiki\DatabaseDatabaseInterface

Represent how a database connection must be implemented.

Summary

Methods
Constants
__construct()
connect()
close()
connected()
create()
update()
delete()
deleteAll()
read()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

__construct()

__construct(string  $details) 

Create a new database handler and logically connect the given database.

Parameters

string $details

the connection string

Throws

\Gishiki\Database\DatabaseException

the error occurred while connecting to the database

\InvalidArgumentException

given details are invalid

connect()

connect(string  $details) 

Logically connect the given database.

Parameters

string $details

the connection string

Throws

\Gishiki\Database\DatabaseException

the error occurred while connecting to the database

\InvalidArgumentException

given details are invalid

close()

close() : void

Close the connection to the database.

connected()

connected() : boolean

Check if the database handler is connected with a real database.

Returns

boolean —

TRUE only if the database connection is alive

create()

create(string  $collection, array|\Gishiki\Algorithms\Collections\CollectionInterface  $data) : mixed

Write data to the database on the given collection/table.

Parameters

string $collection

the name of the collection that will hold the data

array|\Gishiki\Algorithms\Collections\CollectionInterface $data

the collection of data to be written

Throws

\Gishiki\Database\DatabaseException

the error occurred while inserting data to the database

\InvalidArgumentException

the given collection name or data is not a collection of valid values

Returns

mixed —

the unique ID of the inserted data

update()

update(string  $collection, array|\Gishiki\Algorithms\Collections\CollectionInterface  $data, \Gishiki\Database\Runtime\SelectionCriteria  $where) : integer

Update values of documents/records matching the given criteria.

Parameters

string $collection

the name of the collection that will hold the changed data

array|\Gishiki\Algorithms\Collections\CollectionInterface $data

the new data of selected documents/records

\Gishiki\Database\Runtime\SelectionCriteria $where

the criteria used to select documents/records to update

Throws

\Gishiki\Database\DatabaseException

the error occurred while updating data on the database

\InvalidArgumentException

the given collection name or data is not a collection of valid values

Returns

integer —

the number of affected documents/records

delete()

delete(string  $collection, \Gishiki\Database\Runtime\SelectionCriteria  $where) : integer

Remove documents/records matching the given criteria.

Parameters

string $collection

the name of the collection that will be affected

\Gishiki\Database\Runtime\SelectionCriteria $where

the criteria used to select documents/records to update

Throws

\Gishiki\Database\DatabaseException

the error occurred while removing data from the database

\InvalidArgumentException

the given collection name is not a valid collection name

Returns

integer —

the number of removed documents/records

deleteAll()

deleteAll(string  $collection) : integer

Remove EVERY documents/records on the given collection/table.

Parameters

string $collection

the name of the collection that will be affected

Throws

\Gishiki\Database\DatabaseException

the error occurred while removing data from the database

\InvalidArgumentException

the given collection name is not a valid collection name

Returns

integer —

the number of removed documents/records

read()

read(string  $collection, \Gishiki\Database\Runtime\SelectionCriteria  $where, \Gishiki\Database\Runtime\ResultModifier  $mod) : array

Fetch documents/records matching the given criteria.

Parameters

string $collection

the name of the collection that will be searched

\Gishiki\Database\Runtime\SelectionCriteria $where

the criteria used to select documents/records to fetch

\Gishiki\Database\Runtime\ResultModifier $mod

the modifier to be applied to the result set

Throws

\Gishiki\Database\DatabaseException

the error occurred while fetching data from the database

\InvalidArgumentException

the given collection name is not a valid collection name

Returns

array —

the search result expressed as an array of associative arrays