Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit fdc8046

Browse files
committed
add PostgreSQL
1 parent 588338e commit fdc8046

3 files changed

Lines changed: 70 additions & 3 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Deimos\QueryBuilder\Adapter;
4+
5+
use Deimos\QueryBuilder\AbstractAdapter;
6+
7+
class PostgreSQL extends AbstractAdapter
8+
{
9+
10+
protected $port = 5432;
11+
12+
public function dsn()
13+
{
14+
return sprintf(
15+
'%s:host=%s;port=%s;dbname=%s',
16+
$this->name(),
17+
$this->host(),
18+
$this->port(),
19+
$this->dbName()
20+
);
21+
}
22+
23+
/**
24+
* @return array
25+
*/
26+
public function columns()
27+
{
28+
return [];
29+
}
30+
31+
/**
32+
* @param string $string
33+
*
34+
* @return string
35+
*/
36+
public function quote($string)
37+
{
38+
return '"' . str_replace('.', '"."', $string) . '"';
39+
}
40+
41+
/**
42+
* @return string
43+
*/
44+
public function name()
45+
{
46+
return 'pgsql';
47+
}
48+
49+
}

tests/Tests/QueryTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Deimos\QueryBuilder\QueryBuilder;
77
use Deimos\QueryBuilder\RawQuery;
88

9-
class QueryTest extends \PHPUnit_Framework_TestCase
9+
class QueryTest extends \TestCase
1010
{
1111

1212
private $regexp = [
@@ -93,7 +93,8 @@ protected function methodTest($method, $from = 'FROM')
9393
'', 0.0, 10, true
9494
);
9595

96-
if ($this->instructionMethod != 'insert') {
96+
if ($this->instructionMethod !== 'insert')
97+
{
9798
preg_match_all('~' . $this->regexp[1] . '~', $str, $testArray);
9899
unset($testArray[0]);
99100
$this->assertEquals(
@@ -190,7 +191,9 @@ public function testSelectLiveHack()
190191

191192
$Q = $this->prepare('query');
192193

193-
(string)$Q->select([new RawQuery('COUNT(id) as count')])->orderBy(new RawQuery('RAND()'));
194+
$query = (string)$Q->select([new RawQuery('COUNT(id) as count')])->orderBy(new RawQuery('RAND()'));
195+
196+
$this->assertFalse(empty($query));
194197
}
195198

196199
/**

tests/bootstrap.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@
66
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
77

88
$loader->addPsr4('DeimosTest\\', 'tests/src/');
9+
10+
if (class_exists('\\PHPUnit\\Framework\\TestCase'))
11+
{
12+
class TestCase extends \PHPUnit\Framework\TestCase
13+
{
14+
15+
}
16+
}
17+
else
18+
{
19+
class TestCase extends \PHPUnit_Framework_TestCase
20+
{
21+
22+
}
23+
}

0 commit comments

Comments
 (0)