PHP 클래스 LessQL\Database

파일 보기 프로젝트 열기: morris/lessql

보호된 프로퍼티들

프로퍼티 타입 설명
$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