Sledgehammer Framework

DatabaseRepositoryBackend extends RepositoryBackend
in package

Repository backend for database records.

Tags
todo

Validate datatypes before retrieving or removing records, because '12a' will be sillently truncated by mysql to 12

Table of Contents

$cacheTimeout  : string
$configs  : array<string|int, ModelConfig>
The available models in this backend.
$identifier  : string
$junctions  : array<string|int, mixed>|ModelConfig
The junction tables.
$preparedStatements  : array<string|int, mixed>
Prepared statements for get() requests.
__call()  : mixed
Report that the $method doesn't exist.
__callStatic()  : mixed
Report that the $method doesn't exist.
__construct()  : mixed
__get()  : mixed
Report that $property doesn't exist.
__set()  : mixed
Report that $property doesn't exist and set the property to the given $value.
__toString()  : string
The object is used as an string.
add()  : array<string|int, mixed>
INSERT record INTO the database.
all()  : DatabaseCollection
Retrieve all available model-data.
boolToValue()  : string
Convert a boolean to a database value.
delete()  : mixed
Permanently remove an record based on the data.
get()  : array<string|int, mixed>
Load the record from the db.
getSchema()  : array<string|int, mixed>
Get column and relation information from the database.
inspectDatabase()  : mixed
Create model configs based on the tables in the database schema.
related()  : Traversable|array<string|int, mixed>
Retrieve all related model-data.
renameModel()  : mixed
Rename a model and remap the relations to the new name.
renameProperty()  : mixed
Rename a property and remap the relations to the new name.
skipProperty()  : mixed
Remove a property.
update()  : array<string|int, mixed>
Update an existing record.
valueToBool()  : bool
Convert value from the database to a boolean.
valueToInt()  : int
Convert value from the database to an int.
generateWhere()  : string
getSchemaMySql()  : array<string|int, mixed>
Extract the Database schema from a MySQL database.
getSchemaSqlite()  : array<string|int, mixed>
Extract the Database schema from a Sqlite database.
quote()  : mixed
Don't put quotes around number for columns that are assumend to be integers ('id' or ending in '_id').
stripIdSuffix()  : string
Remove the "_id" suffix from a columnname.
stripQuotedValue()  : int

Properties

$configs

The available models in this backend.

public array<string|int, ModelConfig> $configs

array('Model name' => ModelConfig, 'Model2 name' => ModelConfig, ...)

$preparedStatements

Prepared statements for get() requests.

private array<string|int, mixed> $preparedStatements = []

Methods

__call()

Report that the $method doesn't exist.

public __call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__callStatic()

Report that the $method doesn't exist.

public static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__construct()

public __construct([array<string|int, mixed>|string $databases = [] ]) : mixed
Parameters
$databases : array<string|int, mixed>|string = []
Return values
mixed

__get()

Report that $property doesn't exist.

public __get(string $property) : mixed
Parameters
$property : string
Return values
mixed

__set()

Report that $property doesn't exist and set the property to the given $value.

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Return values
mixed

__toString()

The object is used as an string.

public __toString() : string
Return values
string

add()

INSERT record INTO the database.

public add(array<string|int, mixed> $data, array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
$config : array<string|int, mixed>
Return values
array<string|int, mixed>

boolToValue()

Convert a boolean to a database value.

public static boolToValue(bool $bool) : string

Doesn't convert all values. (A tinyint(1) can also be a number or might be null).

Parameters
$bool : bool
Return values
string

delete()

Permanently remove an record based on the data.

public delete(array<string|int, mixed> $row, array<string|int, mixed> $config) : mixed
Parameters
$row : array<string|int, mixed>

The data

$config : array<string|int, mixed>
Return values
mixed

get()

Load the record from the db.

public get(mixed $id, array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
$id : mixed
$config : array<string|int, mixed>
Return values
array<string|int, mixed>

getSchema()

Get column and relation information from the database.

public getSchema(Database $db[, string $prefix = '' ]) : array<string|int, mixed>
Parameters
$db : Database
$prefix : string = ''

Table prefix

Tags
private
Return values
array<string|int, mixed>

inspectDatabase()

Create model configs based on the tables in the database schema.

public inspectDatabase([string $dbLink = 'default' ][, mixed $tablePrefix = '' ]) : mixed
Parameters
$dbLink : string = 'default'
$tablePrefix : mixed = ''
Return values
mixed

Retrieve all related model-data.

public related(mixed $config, mixed $reference, mixed $id) : Traversable|array<string|int, mixed>
Parameters
$config : mixed
$reference : mixed
$id : mixed
Return values
Traversable|array<string|int, mixed>

renameModel()

Rename a model and remap the relations to the new name.

public renameModel(string $from, string $to) : mixed
Parameters
$from : string

Current name

$to : string

The new name

Return values
mixed

renameProperty()

Rename a property and remap the relations to the new name.

public renameProperty(string $model, string $from, string $to) : mixed
Parameters
$model : string

The modelname

$from : string

The current propertyname

$to : string

The new propertyname

Return values
mixed

skipProperty()

Remove a property.

public skipProperty(string $model, string $property) : mixed
Parameters
$model : string

The modelname

$property : string

The current propertyname

Return values
mixed

update()

Update an existing record.

public update(array<string|int, mixed> $new, array<string|int, mixed> $old, array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
$new : array<string|int, mixed>
$old : array<string|int, mixed>
$config : array<string|int, mixed>
Return values
array<string|int, mixed>

valueToBool()

Convert value from the database to a boolean.

public static valueToBool(string $value) : bool

Doesn't convert all values. (tinyint(1) can also be a number or might be null).

Parameters
$value : string
Return values
bool

valueToInt()

Convert value from the database to an int.

public static valueToInt(string $value) : int
Parameters
$value : string
Return values
int

generateWhere()

private generateWhere(array<string|int, mixed> $keys, array<string|int, mixed> $config[, mixed $prepare = false ]) : string
Parameters
$keys : array<string|int, mixed>

Array containing the primay keys

$config : array<string|int, mixed>
$prepare : mixed = false
Return values
string

getSchemaMySql()

Extract the Database schema from a MySQL database.

private getSchemaMySql(Database $db[, mixed $prefix = '' ]) : array<string|int, mixed>
Parameters
$db : Database
$prefix : mixed = ''
Return values
array<string|int, mixed>

schema definition

getSchemaSqlite()

Extract the Database schema from a Sqlite database.

private getSchemaSqlite(mixed $db[, mixed $prefix = false ]) : array<string|int, mixed>
Parameters
$db : mixed
$prefix : mixed = false
Return values
array<string|int, mixed>

schema definition

quote()

Don't put quotes around number for columns that are assumend to be integers ('id' or ending in '_id').

private quote(Database $db, string $column, mixed $value) : mixed
Parameters
$db : Database
$column : string
$value : mixed
Return values
mixed

stripIdSuffix()

Remove the "_id" suffix from a columnname.

private stripIdSuffix(string $column) : string
Parameters
$column : string
Return values
string

stripQuotedValue()

private stripQuotedValue(type $parts, type &$value, type $offset[, type $open = "'" ][, type $close = null ]) : int
Parameters
$parts : type
$value : type
$offset : type
$open : type = "'"
$close : type = null
Return values
int

Search results