Completed
Branch feature/pre-split (b5c37f)
by Anton
03:43
created

PostgresCompiler::compileInsert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 4
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Database\Drivers\Postgres;
10
11
use Spiral\Database\Entities\QueryCompiler as AbstractCompiler;
12
13
/**
14
 * Postgres syntax specific compiler.
15
 */
16
class PostgresCompiler extends AbstractCompiler
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function compileInsert(
22
        string $table,
23
        array $columns,
24
        array $rowsets,
25
        string $primaryKey = ''
26
    ): string {
27
        return parent::compileInsert(
28
                $table,
29
                $columns,
30
                $rowsets
31
            ) . (!empty($primaryKey) ? ' RETURNING ' . $this->quote($primaryKey) : '');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function compileDistinct($distinct): string
38
    {
39
        if (empty($distinct)) {
40
            return '';
41
        }
42
43
        return 'DISTINCT' . (is_string($distinct) ? '(' . $this->quote($distinct) . ')' : '');
44
    }
45
}
46