-
Notifications
You must be signed in to change notification settings - Fork 37
/
Connection.php
87 lines (75 loc) · 2 KB
/
Connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace duxet\Rethinkdb;
use duxet\Rethinkdb\Query\Builder as QueryBuilder;
use duxet\Rethinkdb\Schema\Grammar;
use r;
class Connection extends \Illuminate\Database\Connection
{
/**
* The RethinkDB connection handler.
*
* @var r\Connection
*/
protected $connection;
/**
* Create a new database connection instance.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
$this->database = $config['database'];
$port = isset($config['port']) ? $config['port'] : 28015;
$authKey = isset($config['authKey']) ? $config['authKey'] : null;
// Create the connection
$this->connection = r\connect($config['host'], $port, $this->database, $authKey);
// We need to initialize a query grammar and the query post processors,
// which are both very important parts of the database abstractions -
// so we initialize these to their default values when starting.
$this->useDefaultQueryGrammar();
$this->useDefaultPostProcessor();
$this->schemaGrammar = new Grammar();
}
/**
* Begin a fluent query against a database table.
*
* @param string $table
*
* @return QueryBuilder
*/
public function table($table)
{
$query = new QueryBuilder($this);
return $query->from($table);
}
/**
* Get a RethinkDB connection.
*
* @return \r\Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* Get the elapsed time since a given starting point.
*
* @param int $start
*
* @return float
*/
public function getElapsedTime($start)
{
return parent::getElapsedTime($start);
}
/**
* Get a schema builder instance for the connection.
*
* @return Schema\Builder
*/
public function getSchemaBuilder()
{
return new Schema\Builder($this);
}
}