class VirtualConnection implements VirtualConnectionInterface

VirtualConnection

  • config/xe.php 의 설정에 따라 Illuminate\Database\Connection 관리
  • select query 할 경우 slave 설정의 connection 반환
  • Illuminate\Database\Connection 의 wrapper class
  • Database 의 Proxy 를 처리하기위해 DynamicQuery 사용

사용

Database Connection

$connector = app('xe.db');
$connection = $connector->master();
$connection = $connector->slave();

Query

$connector = app('xe.db');
$query = $connector->table('user');
$result = $connector->table('user')->first();

$proxyConfig = [... config for proxy ...];
$query = $connector->dynamic('tableName', $proxyConfig);

Constants

TYPE_MASTER

master type key name

TYPE_SLAVE

slave type key name

DEFAULT_CONNECTION_NAME

default database connection name (config/database.php 의 기본 connection 설정 이름)

Properties

protected DatabaseCoupler $coupler
protected DynamicQuery $queryBuilder
protected string $name connector name
protected string $master config/database.php config name for create master connection instance
protected string $slave config/database.php config name for create slave connection instance
protected string $tablePrefix
protected array $connections connections list

  • config/xe.php database key 에 따라 master, slave 로 구분해서 /Illuminate/Database/Connection 을 갖는다.
protected int $fetchMode The default fetch mode of the connection.
static protected Repository $cache Cache store instance
protected int $minutes The number of minutes to store cache items.

Methods

__construct(DatabaseCoupler $coupler, string $name, array $config)

Create instance

int
getFetchMode()

Get the default fetch mode for the connection.

int
setFetchMode(int $fetchMode)

Set the default fetch mode for the connection.

string
getName()

get name for connector

Connection
getDefaultConnection()

DynamicQuery 에서 사용 \Illuminate\Database\Query\Builder 를 만들 때 Connection 이 필요함.

Builder
getSchemaBuilder()

Get a schema builder instance for the connection.

string
getTablePrefix()

Get table prefix name.

void
setNames(array $config)

set connection name.

mixed
fixConfig(array $config)

설정 정보 확인 master, slave 설정이 없을 경우 기본 설정을 넣어 줌

Connection
connectionName(array $names)

$type 에서 사용 될 connection name 결정.

getProxyManager()

get ProxyManager.

Connection
connection(string $type = self::DEFAULT_CONNECTION_NAME)

get connection

Connection
master()

get master connection

Connection
slave()

get slave connection

ConnectionInterface
getConnection(string $type = 'select')

get connection by $queryType.

table(string $table)

Begin a fluent query against a database table.

dynamic(string $table, array $options = array(), bool $proxy = true)

DynamicField 를 이용해 처리.

query()

Get a new query builder instance.

Expression
raw(mixed $value)

Get a new raw query expression.

mixed
selectOne(string $query, array $bindings = array())

Run a select statement and return a single result.

array
select(string $query, array $bindings = array())

Run a select statement against the database.

bool
insert(string $query, array $bindings = array())

Run an insert statement against the database.

int
update(string $query, array $bindings = array())

Run an update statement against the database.

int
delete(string $query, array $bindings = array())

Run a delete statement against the database.

bool
statement(string $query, array $bindings = array())

Execute an SQL statement and return the boolean result.

int
affectingStatement(string $query, array $bindings = array())

Run an SQL statement and get the number of rows affected.

bool
unprepared(string $query)

Run a raw, unprepared query against the PDO connection.

array
prepareBindings(array $bindings)

Prepare the query bindings for execution.

mixed
transaction(Closure $callback)

Execute a Closure within a transaction.

transactionHandler()

get TransactionHandler

void
beginTransaction()

Start a new database transaction.

void
commit()

Commit the active database transaction.

void
rollBack()

Rollback the active database transaction.

int
transactionLevel()

Get the number of active transactions.

array
pretend(Closure $callback)

Execute the given callback in "dry run" mode.

array
getSchema(string $table)

return database table schema

bool
setSchemaCache(string $table, bool $force = false)

set database table schema

static void
setCache(Repository $cache)

Set the cache store.

static Repository|null
getCache()

Get the cache store.

void
setCacheExpire(int $minutes)

Set the number of minutes to store cache items.

mixed
__call(string $method, array $parameters)

인터페이스에 정의되지 않은 기능을 수행 하기 위함.

Details

at line 156
__construct(DatabaseCoupler $coupler, string $name, array $config)

Create instance

Parameters

DatabaseCoupler $coupler database coupler
string $name connector name
array $config database config (xe.php file 의 database 설정)

at line 168
int getFetchMode()

Get the default fetch mode for the connection.

Return Value

int

at line 180
int setFetchMode(int $fetchMode)

Set the default fetch mode for the connection.

Parameters

int $fetchMode fetch mode

Return Value

int

See also

PDO fetch method

at line 190
string getName()

get name for connector

Return Value

string

at line 201
Connection getDefaultConnection()

DynamicQuery 에서 사용 \Illuminate\Database\Query\Builder 를 만들 때 Connection 이 필요함.

Return Value

Connection

at line 211
Builder getSchemaBuilder()

Get a schema builder instance for the connection.

Return Value

Builder

at line 221
string getTablePrefix()

Get table prefix name.

Return Value

string

at line 233
private void setNames(array $config)

set connection name.

설정된 master, slave 이름들에서 사용 할 이름을 선택.

Parameters

array $config database config

Return Value

void

at line 247
private mixed fixConfig(array $config)

설정 정보 확인 master, slave 설정이 없을 경우 기본 설정을 넣어 줌

Parameters

array $config database config

Return Value

mixed

at line 266
private Connection connectionName(array $names)

$type 에서 사용 될 connection name 결정.

Parameters

array $names connection 이름

Return Value

Connection

at line 278
ProxyManager getProxyManager()

get ProxyManager.

DynamicQuery 에서 VirtualConnection 를 주입 받아 사용.

Return Value

ProxyManager

at line 289
Connection connection(string $type = self::DEFAULT_CONNECTION_NAME)

get connection

Parameters

string $type master or slave

Return Value

Connection

at line 303
Connection master()

get master connection

Return Value

Connection

at line 313
Connection slave()

get slave connection

Return Value

Connection

at line 326
ConnectionInterface getConnection(string $type = 'select')

get connection by $queryType.

'select' 쿼리일 경우 $slaveConnection 을 넘겨주고 그렇지 않을 경우 $masterConnection 을 반환. database 를 쿼리 실행 시 연결.

Parameters

string $type query type

Return Value

ConnectionInterface

at line 342
DynamicQuery table(string $table)

Begin a fluent query against a database table.

ProxyManager 를 통한 처리를 하지 않음.

Parameters

string $table table name

Return Value

DynamicQuery

at line 356
DynamicQuery dynamic(string $table, array $options = array(), bool $proxy = true)

DynamicField 를 이용해 처리.

ProxyManager 에 register 된 Proxy 들을 처리.

Parameters

string $table table name
array $options proxy options
bool $proxy use proxy

Return Value

DynamicQuery

at line 374
DynamicQuery query()

Get a new query builder instance.

Return Value

DynamicQuery

at line 386
Expression raw(mixed $value)

Get a new raw query expression.

Parameters

mixed $value value

Return Value

Expression

at line 398
mixed selectOne(string $query, array $bindings = array())

Run a select statement and return a single result.

Parameters

string $query query
array $bindings bindings

Return Value

mixed

at line 410
array select(string $query, array $bindings = array())

Run a select statement against the database.

Parameters

string $query query
array $bindings bindings

Return Value

array

at line 422
bool insert(string $query, array $bindings = array())

Run an insert statement against the database.

Parameters

string $query query
array $bindings bindings

Return Value

bool

at line 434
int update(string $query, array $bindings = array())

Run an update statement against the database.

Parameters

string $query query
array $bindings bindings

Return Value

int

at line 446
int delete(string $query, array $bindings = array())

Run a delete statement against the database.

Parameters

string $query query
array $bindings bindings

Return Value

int

at line 458
bool statement(string $query, array $bindings = array())

Execute an SQL statement and return the boolean result.

Parameters

string $query query
array $bindings bindings

Return Value

bool

at line 470
int affectingStatement(string $query, array $bindings = array())

Run an SQL statement and get the number of rows affected.

Parameters

string $query query
array $bindings bindings

Return Value

int

at line 481
bool unprepared(string $query)

Run a raw, unprepared query against the PDO connection.

Parameters

string $query query

Return Value

bool

at line 492
array prepareBindings(array $bindings)

Prepare the query bindings for execution.

Parameters

array $bindings bindings

Return Value

array

at line 505
mixed transaction(Closure $callback)

Execute a Closure within a transaction.

Parameters

Closure $callback closure

Return Value

mixed

Exceptions

Exception
Throwable

at line 531
TransactionHandler transactionHandler()

get TransactionHandler

Return Value

TransactionHandler

at line 541
void beginTransaction()

Start a new database transaction.

DatabaseHandler 를 통해서 transaction 관리.

Return Value

void

at line 552
void commit()

Commit the active database transaction.

DatabaseHandler 를 통해서 commit.

Return Value

void

at line 562
void rollBack()

Rollback the active database transaction.

Return Value

void

at line 572
int transactionLevel()

Get the number of active transactions.

Return Value

int

at line 583
array pretend(Closure $callback)

Execute the given callback in "dry run" mode.

Parameters

Closure $callback closure

Return Value

array

at line 594
array getSchema(string $table)

return database table schema

Parameters

string $table table name

Return Value

array

at line 614
bool setSchemaCache(string $table, bool $force = false)

set database table schema

Parameters

string $table table name
bool $force force

Return Value

bool

at line 637
static void setCache(Repository $cache)

Set the cache store.

Parameters

Repository $cache cache instance

Return Value

void

at line 647
static Repository|null getCache()

Get the cache store.

Return Value

Repository|null

at line 658
void setCacheExpire(int $minutes)

Set the number of minutes to store cache items.

Parameters

int $minutes number of minutes

Return Value

void

at line 671
mixed __call(string $method, array $parameters)

인터페이스에 정의되지 않은 기능을 수행 하기 위함.

Illuminate\Database\Connection 의 method 실행.

Parameters

string $method method name
array $parameters parameters

Return Value

mixed