\Localgod\Tick\StorageSqlStorage

Tick sql storage implementation

All databases supported by PDO should work, but it has only been tested with mysql and sqlite.

Summary

Methods
Properties
Constants
__construct()
getConnection()
closeConnection()
get()
insert()
update()
remove()
exists()
count()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
limit()
orderBy()
criteria()
prepareCriteria()
convertDateTime()
interpolateQuery()
$connection
N/A

Properties

$connection

$connection : \PDO

Database connection

Type

\PDO

Methods

__construct()

__construct(\PDO  $connection) 

Set the database connection

Parameters

\PDO $connection

Database connection

getConnection()

getConnection() : \PDO

Get storage connection

Returns

\PDO —

A PDO instance

closeConnection()

closeConnection() : void

Close storage connection

get()

get(string  $collection, array  $fields, array  $criterias, array  $order = array(), boolean  $direction = true, string  $limit = '', string  $offset = '') : array

Get entities in storage

Parameters

string $collection

Collection to search

array $fields

Properties to get

array $criterias

Criterias to search by

array $order

Order result

boolean $direction

Order direction

string $limit

Limit result

string $offset

Offset result

Returns

array —

Array with Associative arrays with fieldname=>value

insert()

insert(string  $collection, array  $data) : integer

Insert entity to storage

Parameters

string $collection

Collection to insert into

array $data

Associative array with fieldname => value

Returns

integer —

Id of the object inserted

update()

update(string  $collection, array  $data, array  $criterias) : void

Update entity in storage

Parameters

string $collection

Collection to update

array $data

Associative array with fieldname=>value

array $criterias

Criteria of the object to update

remove()

remove(string  $collection, array  $criterias) : void

Remove entity from storage

Parameters

string $collection

Collection to search

array $criterias

Criteria of the object to remove

exists()

exists(string  $collection, array  $criterias) : boolean

Entity exists in storage

Parameters

string $collection

Collection to search

array $criterias

Criteria of the object to check for

Returns

boolean —

if the entity exists

count()

count(string  $collection, array  $criterias) : integer

Count number of entities matching the criteria

Parameters

string $collection

Collection to search

array $criterias

Criteria of the object to check for

Returns

integer

limit()

limit(integer  $limit, integer  $offset) : string

Convert limit criteria to limit clause

Parameters

integer $limit

Limit

integer $offset

Offset

Returns

string —

Sql representation of a limit clause

orderBy()

orderBy(array  $order, boolean  $direction = true) : string

Convert order criteria to order clause

Parameters

array $order

Order

boolean $direction

Direction of the order (true = ascending, false descending)

Returns

string —

Sql representation of a order clause

criteria()

criteria(array  $criterias) : array

Get criteria values

Parameters

array $criterias

List of criterias

Returns

array —

values to fill where clause

prepareCriteria()

prepareCriteria(array  $criterias) : string

Convert criteria to where clause

Parameters

array $criterias

List of criterias

Returns

string —

Sql representation of a where clause

convertDateTime()

convertDateTime(\DateTime  $value = null) : string

Convert DateTime object to a valid database representation

Parameters

\DateTime $value

Value to convert

Returns

string —

Sql representation of a datetime value

interpolateQuery()

interpolateQuery(string  $query, array  $params) : string

Replaces any parameter placeholders in a query with the value of that parameter.

Useful for debugging. Assumes anonymous parameters from $params are are in the same order as specified in $query

Parameters

string $query

The sql query with parameter placeholders

array $params

The array of substitution parameters

Returns

string —

The interpolated query