PHP Класс LessQL\Database

Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$aliases array
$backReferences array
$identifierDelimiter string
$primary array
$queryCallback null | callable
$references array
$required array
$rewrite null | callable
$sequences array

Открытые методы

Метод Описание
__call ( string $name, array $args ) : Result | lessql\Row | null Returns a result for table $name.
__construct ( PDO $pdo ) Constructor. Sets PDO to exception mode.
begin ( ) : boolean Begin a transaction
commit ( ) : boolean Commit changes of transaction
createResult ( Database | Result | lessql\Row $parent, string $name ) : Result Create a result bound to $parent using table or association $name.
createRow ( string $name, array $properties = [], Result | null $result = null ) : lessql\Row Create a row from given properties.
delete ( string $table, array $where = [], array $params = [] ) : PDOStatement Execute delete query and return statement
format ( mixed $value ) : string Format a value for SQL, e.g. DateTime objects
getAlias ( string $alias ) : string Get alias of a table
getBackReference ( string $table, string $name ) : string Get a back reference key for an association on a table
getIdentifierDelimiter ( ) : string Get identifier delimiter
getPrimary ( string $table ) : string | array Get primary key of a table, may be array for compound keys
getReference ( string $table, string $name ) : string Get a reference key for an association on a table
getRequired ( string $table ) : array Get a map of required columns of a table
getSequence ( string $table ) : null | string Get primary sequence name of table (used in INSERT by Postgres)
getSuffix ( array $where, array $orderBy = [], integer | null $limitCount = null, integer | null $limitOffset = null ) : string Return WHERE/LIMIT/ORDER suffix for queries
insert ( string $table, array $rows, string | null $method = null ) : PDOStatement | null Insert one ore more rows into a table
is ( string $column, string | array $value, boolean $not = false ) : string Build an SQL condition expressing that "$column is $value", or "$column is in $value" if $value is an array. Handles null and literals like new Literal( "NOW()" ) correctly.
isNot ( string $column, string | array $value ) : string Build an SQL condition expressing that "$column is not $value" or "$column is not in $value" if $value is an array. Handles null and literals like new Literal( "NOW()" ) correctly.
isRequired ( string $table, string $column ) : boolean Is a column of a table required for saving? Default is no
lastInsertId ( string | null $sequence = null ) : string Return last inserted id
literal ( string $value ) : lessql\Literal Create a SQL Literal
onQuery ( string $query, array $params = [] ) Calls the query callback, if any
prepare ( string $query ) : PDOStatement Prepare an SQL statement
query ( string $query ) : PDOStatement Execute an SQL statement directly
quote ( mixed $value ) : string Quote a value for SQL
quoteIdentifier ( string $identifier ) : string Quote identifier
rewriteTable ( string $table ) : string Get rewritten table name
rollback ( ) : boolean Rollback any changes during transaction
select ( string $table, $options = [] ) : PDOStatement Select rows from a table
setAlias ( string $alias, string $table ) Set alias of a table
setBackReference ( string $table, string $name, string $key ) Set a back reference key for an association on a table
setIdentifierDelimiter ( string | null $d ) Sets delimiter used when quoting identifiers.
setPrimary ( string $table, string | array $key ) Set primary key of a table.
setQueryCallback ( callable $callback ) Set the query callback
setReference ( string $table, string $name, string $key ) Set a reference key for an association on a table
setRequired ( string $table, string $column ) Set a column to be required for saving Any primary key that is not auto-generated should be required Compound primary keys are required by default
setRewrite ( callable $rewrite ) Set table rewrite function For example, it could add a prefix
setSequence ( string $table, string $sequence ) Set primary sequence name of table
table ( $name, integer | null $id = null ) : Result | lessql\Row | null Returns a result for table $name.
update ( string $table, array $data, array $where = [], array $params = [] ) : null | PDOStatement Execute update query and return statement

Защищенные методы

Метод Описание
getColumns ( array $rows ) : array Get list of all columns used in the given rows
insertBatch ( string $table, array $rows ) : PDOStatement | null Insert rows using a single batch query
insertDefault ( string $table, array $rows ) : PDOStatement | null Insert rows using one query per row
insertHead ( string $table, array $columns ) : string Build head of INSERT query (without values)
insertPrepared ( string $table, array $rows ) : PDOStatement | null Insert rows using a prepared query
valueLists ( array $rows, array $columns ) : array Build lists of quoted values for INSERT

Описание методов

__call() публичный Метод

If $id is given, return the row with that id. Examples: $db->user()->where( ... ) $db->user( 1 )
public __call ( string $name, array $args ) : Result | lessql\Row | null
$name string
$args array
Результат Result | lessql\Row | null

__construct() публичный Метод

Constructor. Sets PDO to exception mode.
public __construct ( PDO $pdo )
$pdo PDO

begin() публичный Метод

Begin a transaction
public begin ( ) : boolean
Результат boolean

commit() публичный Метод

Commit changes of transaction
public commit ( ) : boolean
Результат boolean

createResult() публичный Метод

$parent may be the database, a result, or a row
public createResult ( Database | Result | lessql\Row $parent, string $name ) : Result
$parent Database | Result | lessql\Row
$name string
Результат Result

createRow() публичный Метод

Optionally bind it to the given result.
public createRow ( string $name, array $properties = [], Result | null $result = null ) : lessql\Row
$name string
$properties array
$result Result | null
Результат lessql\Row

delete() публичный Метод

DELETE FROM $table [WHERE $where]
public delete ( string $table, array $where = [], array $params = [] ) : PDOStatement
$table string
$where array
$params array
Результат PDOStatement

format() публичный Метод

Format a value for SQL, e.g. DateTime objects
public format ( mixed $value ) : string
$value mixed
Результат string

getAlias() публичный Метод

Get alias of a table
public getAlias ( string $alias ) : string
$alias string
Результат string

getBackReference() публичный Метод

"How would $table be referenced by another table under $name?" Convention is "$table_id"
public getBackReference ( string $table, string $name ) : string
$table string
$name string
Результат string

getColumns() защищенный Метод

Get list of all columns used in the given rows
protected getColumns ( array $rows ) : array
$rows array
Результат array

getIdentifierDelimiter() публичный Метод

Get identifier delimiter
public getIdentifierDelimiter ( ) : string
Результат string

getPrimary() публичный Метод

Convention is "id"
public getPrimary ( string $table ) : string | array
$table string
Результат string | array

getReference() публичный Метод

"How would $table reference another table under $name?" Convention is "$name_id"
public getReference ( string $table, string $name ) : string
$table string
$name string
Результат string

getRequired() публичный Метод

Get a map of required columns of a table
public getRequired ( string $table ) : array
$table string
Результат array

getSequence() публичный Метод

Conventions is "$tableRewritten_$primary_seq"
public getSequence ( string $table ) : null | string
$table string
Результат null | string

getSuffix() публичный Метод

Return WHERE/LIMIT/ORDER suffix for queries
public getSuffix ( array $where, array $orderBy = [], integer | null $limitCount = null, integer | null $limitOffset = null ) : string
$where array
$orderBy array
$limitCount integer | null
$limitOffset integer | null
Результат string

insert() публичный Метод

The $method parameter selects one of the following insert methods: "prepared": Prepare a query and execute it once per row using bound params Does not support Literals in row data (PDO limitation) "batch": Create a single query mit multiple value lists Supports Literals, but not supported everywhere default: Execute one INSERT per row Supports Literals, supported everywhere, slow for many rows
public insert ( string $table, array $rows, string | null $method = null ) : PDOStatement | null
$table string
$rows array
$method string | null
Результат PDOStatement | null

insertBatch() защищенный Метод

Insert rows using a single batch query
protected insertBatch ( string $table, array $rows ) : PDOStatement | null
$table string
$rows array
Результат PDOStatement | null

insertDefault() защищенный Метод

Insert rows using one query per row
protected insertDefault ( string $table, array $rows ) : PDOStatement | null
$table string
$rows array
Результат PDOStatement | null

insertHead() защищенный Метод

Build head of INSERT query (without values)
protected insertHead ( string $table, array $columns ) : string
$table string
$columns array
Результат string

insertPrepared() защищенный Метод

Insert rows using a prepared query
protected insertPrepared ( string $table, array $rows ) : PDOStatement | null
$table string
$rows array
Результат PDOStatement | null

is() публичный Метод

Build an SQL condition expressing that "$column is $value", or "$column is in $value" if $value is an array. Handles null and literals like new Literal( "NOW()" ) correctly.
public is ( string $column, string | array $value, boolean $not = false ) : string
$column string
$value string | array
$not boolean
Результат string

isNot() публичный Метод

Build an SQL condition expressing that "$column is not $value" or "$column is not in $value" if $value is an array. Handles null and literals like new Literal( "NOW()" ) correctly.
public isNot ( string $column, string | array $value ) : string
$column string
$value string | array
Результат string

isRequired() публичный Метод

Is a column of a table required for saving? Default is no
public isRequired ( string $table, string $column ) : boolean
$table string
$column string
Результат boolean

lastInsertId() публичный Метод

Return last inserted id
public lastInsertId ( string | null $sequence = null ) : string
$sequence string | null
Результат string

literal() публичный Метод

Create a SQL Literal
public literal ( string $value ) : lessql\Literal
$value string
Результат lessql\Literal

onQuery() публичный Метод

Calls the query callback, if any
public onQuery ( string $query, array $params = [] )
$query string
$params array

prepare() публичный Метод

Prepare an SQL statement
public prepare ( string $query ) : PDOStatement
$query string
Результат PDOStatement

query() публичный Метод

Execute an SQL statement directly
public query ( string $query ) : PDOStatement
$query string
Результат PDOStatement

quote() публичный Метод

Quote a value for SQL
public quote ( mixed $value ) : string
$value mixed
Результат string

quoteIdentifier() публичный Метод

Quote identifier
public quoteIdentifier ( string $identifier ) : string
$identifier string
Результат string

rewriteTable() публичный Метод

Get rewritten table name
public rewriteTable ( string $table ) : string
$table string
Результат string

rollback() публичный Метод

Rollback any changes during transaction
public rollback ( ) : boolean
Результат boolean

select() публичный Метод

Select rows from a table
public select ( string $table, $options = [] ) : PDOStatement
$table string
Результат PDOStatement

setAlias() публичный Метод

Set alias of a table
public setAlias ( string $alias, string $table )
$alias string
$table string

setBackReference() публичный Метод

Set a back reference key for an association on a table
public setBackReference ( string $table, string $name, string $key )
$table string
$name string
$key string

setIdentifierDelimiter() публичный Метод

Should be backtick or double quote. Set to null to disable quoting.

setPrimary() публичный Метод

Compound keys may be passed as an array. Always set compound primary keys explicitly with this method.
public setPrimary ( string $table, string | array $key )
$table string
$key string | array

setQueryCallback() публичный Метод

Set the query callback
public setQueryCallback ( callable $callback )
$callback callable

setReference() публичный Метод

Set a reference key for an association on a table
public setReference ( string $table, string $name, string $key )
$table string
$name string
$key string

setRequired() публичный Метод

Set a column to be required for saving Any primary key that is not auto-generated should be required Compound primary keys are required by default
public setRequired ( string $table, string $column )
$table string
$column string

setRewrite() публичный Метод

Set table rewrite function For example, it could add a prefix
public setRewrite ( callable $rewrite )
$rewrite callable

setSequence() публичный Метод

Set primary sequence name of table
public setSequence ( string $table, string $sequence )
$table string
$sequence string

table() публичный Метод

If $id is given, return the row with that id.
public table ( $name, integer | null $id = null ) : Result | lessql\Row | null
$name
$id integer | null
Результат Result | lessql\Row | null

update() публичный Метод

UPDATE $table SET $data [WHERE $where]
public update ( string $table, array $data, array $where = [], array $params = [] ) : null | PDOStatement
$table string
$data array
$where array
$params array
Результат null | PDOStatement

valueLists() защищенный Метод

Build lists of quoted values for INSERT
protected valueLists ( array $rows, array $columns ) : array
$rows array
$columns array
Результат array

Описание свойств

$aliases защищенное свойство

protected array $aliases
Результат array

$backReferences защищенное свойство

protected array $backReferences
Результат array

$identifierDelimiter защищенное свойство

protected string $identifierDelimiter
Результат string

$primary защищенное свойство

protected array $primary
Результат array

$queryCallback защищенное свойство

protected null|callable $queryCallback
Результат null | callable

$references защищенное свойство

protected array $references
Результат array

$required защищенное свойство

protected array $required
Результат array

$rewrite защищенное свойство

protected null|callable $rewrite
Результат null | callable

$sequences защищенное свойство

protected array $sequences
Результат array