PHP Class Xpressengine\Database\VirtualConnection

* config/xe.php 의 설정에 따라 Illuminate\Database\Connection 관리 * select query 할 경우 slave 설정의 connection 반환 * Illuminate\Database\Connection 의 wrapper class * Database 의 Proxy 를 처리하기위해 DynamicQuery 사용 ## 사용 ### Database Connection php $connector = app('xe.db'); $connection = $connector->master(); $connection = $connector->slave(); ### Query php $connector = app('xe.db'); $query = $connector->table('user'); $result = $connector->table('user')->first(); $proxyConfig = [... config for proxy ...]; $query = $connector->dynamic('tableName', $proxyConfig);
Author: XE Developers ([email protected])
Inheritance: implements Xpressengine\Database\VirtualConnectionInterface
ファイルを表示 Open project: xpressengine/xpressengine Class Usage Examples

Protected Properties

Property Type Description
$connections array php $connections = [ 'master' => /Illuminate/Database/Connection, 'slave' => /Illuminate/Database/Connection, ]
$coupler DatabaseCoupler
$fetchMode integer The default fetch mode of the connection.
$master string config/database.php config name for create master connection instance
$name string connector name
$queryBuilder DynamicQuery
$slave string config/database.php config name for create slave connection instance
$tablePrefix string

Public Methods

Method Description
__call ( string $method, array $parameters ) : mixed 인터페이스에 정의되지 않은 기능을 수행 하기 위함.
__construct ( DatabaseCoupler $coupler, string $name, array $config ) Create instance
affectingStatement ( string $query, array $bindings = [] ) : integer Run an SQL statement and get the number of rows affected.
beginTransaction ( ) : void Start a new database transaction.
commit ( ) : void Commit the active database transaction.
connection ( string $type = self::DEFAULT_CONNECTION_NAME ) : Connection get connection
delete ( string $query, array $bindings = [] ) : integer Run a delete statement against the database.
dynamic ( string $table, array $options = [], boolean $proxy = true ) : DynamicQuery DynamicField 를 이용해 처리.
getConnection ( string $type = 'select' ) : Illuminate\Database\ConnectionInterface get connection by $queryType.
getDefaultConnection ( ) : Connection DynamicQuery 에서 사용 \Illuminate\Database\Query\Builder 를 만들 때 Connection 이 필요함.
getFetchMode ( ) : integer Get the default fetch mode for the connection.
getName ( ) : string get name for connector
getProxyManager ( ) : ProxyManager get ProxyManager.
getSchema ( string $table ) : array return database table schema
getSchemaBuilder ( ) : Illuminate\Database\Schema\Builder Get a schema builder instance for the connection.
getTablePrefix ( ) : string Get table prefix name.
insert ( string $query, array $bindings = [] ) : boolean Run an insert statement against the database.
master ( ) : Connection get master connection
prepareBindings ( array $bindings ) : array Prepare the query bindings for execution.
pretend ( Closure $callback ) : array Execute the given callback in "dry run" mode.
query ( ) : DynamicQuery Get a new query builder instance.
raw ( mixed $value ) : Illuminate\Database\Query\Expression Get a new raw query expression.
rollBack ( ) : void Rollback the active database transaction.
select ( string $query, array $bindings = [] ) : array Run a select statement against the database.
selectOne ( string $query, array $bindings = [] ) : mixed Run a select statement and return a single result.
setFetchMode ( integer $fetchMode ) : integer Set the default fetch mode for the connection.
setSchemaCache ( string $table, boolean $force = false ) : boolean set database table schema
slave ( ) : Connection get slave connection
statement ( string $query, array $bindings = [] ) : boolean Execute an SQL statement and return the boolean result.
table ( string $table ) : DynamicQuery Begin a fluent query against a database table.
transaction ( Closure $callback ) : mixed Execute a Closure within a transaction.
transactionHandler ( ) : TransactionHandler get TransactionHandler
transactionLevel ( ) : integer Get the number of active transactions.
unprepared ( string $query ) : boolean Run a raw, unprepared query against the PDO connection.
update ( string $query, array $bindings = [] ) : integer Run an update statement against the database.

Private Methods

Method Description
connectionName ( array $names ) : Connection $type 에서 사용 될 connection name 결정.
fixConfig ( array $config ) : mixed 설정 정보 확인 master, slave 설정이 없을 경우 기본 설정을 넣어 줌
setNames ( array $config ) : void set connection name.

Method Details

__call() public method

Illuminate\Database\Connection 의 method 실행.
public __call ( string $method, array $parameters ) : mixed
$method string method name
$parameters array parameters
return mixed

__construct() public method

Create instance
public __construct ( DatabaseCoupler $coupler, string $name, array $config )
$coupler DatabaseCoupler database coupler
$name string connector name
$config array database config (xe.php file 의 database 설정)

affectingStatement() public method

Run an SQL statement and get the number of rows affected.
public affectingStatement ( string $query, array $bindings = [] ) : integer
$query string query
$bindings array bindings
return integer

beginTransaction() public method

DatabaseHandler 를 통해서 transaction 관리.
public beginTransaction ( ) : void
return void

commit() public method

DatabaseHandler 를 통해서 commit.
public commit ( ) : void
return void

connection() public method

get connection
public connection ( string $type = self::DEFAULT_CONNECTION_NAME ) : Connection
$type string master or slave
return Illuminate\Database\Connection

delete() public method

Run a delete statement against the database.
public delete ( string $query, array $bindings = [] ) : integer
$query string query
$bindings array bindings
return integer

dynamic() public method

ProxyManager 에 register 된 Proxy 들을 처리.
public dynamic ( string $table, array $options = [], boolean $proxy = true ) : DynamicQuery
$table string table name
$options array proxy options
$proxy boolean use proxy
return DynamicQuery

getConnection() public method

'select' 쿼리일 경우 $slaveConnection 을 넘겨주고 그렇지 않을 경우 $masterConnection 을 반환. database 를 쿼리 실행 시 연결.
public getConnection ( string $type = 'select' ) : Illuminate\Database\ConnectionInterface
$type string query type
return Illuminate\Database\ConnectionInterface

getDefaultConnection() public method

DynamicQuery 에서 사용 \Illuminate\Database\Query\Builder 를 만들 때 Connection 이 필요함.
public getDefaultConnection ( ) : Connection
return Illuminate\Database\Connection

getFetchMode() public method

Get the default fetch mode for the connection.
public getFetchMode ( ) : integer
return integer

getName() public method

get name for connector
public getName ( ) : string
return string

getProxyManager() public method

DynamicQuery 에서 VirtualConnection 를 주입 받아 사용.
public getProxyManager ( ) : ProxyManager
return ProxyManager

getSchema() public method

return database table schema
public getSchema ( string $table ) : array
$table string table name
return array

getSchemaBuilder() public method

Get a schema builder instance for the connection.
public getSchemaBuilder ( ) : Illuminate\Database\Schema\Builder
return Illuminate\Database\Schema\Builder

getTablePrefix() public method

Get table prefix name.
public getTablePrefix ( ) : string
return string

insert() public method

Run an insert statement against the database.
public insert ( string $query, array $bindings = [] ) : boolean
$query string query
$bindings array bindings
return boolean

master() public method

get master connection
public master ( ) : Connection
return Illuminate\Database\Connection

prepareBindings() public method

Prepare the query bindings for execution.
public prepareBindings ( array $bindings ) : array
$bindings array bindings
return array

pretend() public method

Execute the given callback in "dry run" mode.
public pretend ( Closure $callback ) : array
$callback Closure closure
return array

query() public method

Get a new query builder instance.
public query ( ) : DynamicQuery
return DynamicQuery

raw() public method

Get a new raw query expression.
public raw ( mixed $value ) : Illuminate\Database\Query\Expression
$value mixed value
return Illuminate\Database\Query\Expression

rollBack() public method

Rollback the active database transaction.
public rollBack ( ) : void
return void

select() public method

Run a select statement against the database.
public select ( string $query, array $bindings = [] ) : array
$query string query
$bindings array bindings
return array

selectOne() public method

Run a select statement and return a single result.
public selectOne ( string $query, array $bindings = [] ) : mixed
$query string query
$bindings array bindings
return mixed

setFetchMode() public method

Set the default fetch mode for the connection.
See also: PDO fetch method
public setFetchMode ( integer $fetchMode ) : integer
$fetchMode integer fetch mode
return integer

setSchemaCache() public method

set database table schema
public setSchemaCache ( string $table, boolean $force = false ) : boolean
$table string table name
$force boolean force
return boolean

slave() public method

get slave connection
public slave ( ) : Connection
return Illuminate\Database\Connection

statement() public method

Execute an SQL statement and return the boolean result.
public statement ( string $query, array $bindings = [] ) : boolean
$query string query
$bindings array bindings
return boolean

table() public method

ProxyManager 를 통한 처리를 하지 않음.
public table ( string $table ) : DynamicQuery
$table string table name
return DynamicQuery

transaction() public method

Execute a Closure within a transaction.
public transaction ( Closure $callback ) : mixed
$callback Closure closure
return mixed

transactionHandler() public method

get TransactionHandler
public transactionHandler ( ) : TransactionHandler
return TransactionHandler

transactionLevel() public method

Get the number of active transactions.
public transactionLevel ( ) : integer
return integer

unprepared() public method

Run a raw, unprepared query against the PDO connection.
public unprepared ( string $query ) : boolean
$query string query
return boolean

update() public method

Run an update statement against the database.
public update ( string $query, array $bindings = [] ) : integer
$query string query
$bindings array bindings
return integer

Property Details

$connections protected_oe property

php $connections = [ 'master' => /Illuminate/Database/Connection, 'slave' => /Illuminate/Database/Connection, ]
protected array $connections
return array

$coupler protected_oe property

protected DatabaseCoupler,Xpressengine\Database $coupler
return DatabaseCoupler

$fetchMode protected_oe property

The default fetch mode of the connection.
protected int $fetchMode
return integer

$master protected_oe property

config/database.php config name for create master connection instance
protected string $master
return string

$name protected_oe property

connector name
protected string $name
return string

$queryBuilder protected_oe property

protected DynamicQuery,Xpressengine\Database $queryBuilder
return DynamicQuery

$slave protected_oe property

config/database.php config name for create slave connection instance
protected string $slave
return string

$tablePrefix protected_oe property

protected string $tablePrefix
return string