• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

letsdrink / ouzo / 4784818091

pending completion
4784818091

push

github

Bartosz BaƄkowski
Fixed tests.

4833 of 5741 relevant lines covered (84.18%)

33.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.63
/src/Ouzo/Core/Db/Dialect/PostgresDialect.php
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6

7
namespace Ouzo\Db\Dialect;
8

9
use Ouzo\Db\OnConflict;
10
use Ouzo\Db\Query;
11
use Ouzo\Utilities\Arrays;
12
use Ouzo\Utilities\Joiner;
13

14
class PostgresDialect extends Dialect
15
{
16
    public function getConnectionErrorCodes(): array
17
    {
18
        return ['57000', '57014', '57P01', '57P02', '57P03'];
1✔
19
    }
20

21
    public function getErrorCode(array $errorInfo): mixed
22
    {
23
        return Arrays::getValue($errorInfo, 0);
1✔
24
    }
25

26
    public function batchInsert(string $table, string $primaryKey, $columns, $batchSize, ?OnConflict $onConflict): string
27
    {
28
        $valueClause = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')';
×
29
        $valueClauses = implode(', ', array_fill(0, $batchSize, $valueClause));
×
30
        $joinedColumns = implode(', ', $columns);
×
31
        $sql = "INSERT INTO {$table} ($joinedColumns) VALUES $valueClauses";
×
32

33
        if ($onConflict) {
×
34
            if ($onConflict->isDoNothingAction()) {
×
35
                $sql .= $this->onConflictDoNothing();
×
36
            }
37
            if ($onConflict->isUpdateAction()) {
×
38
                $query = new Query();
×
39
                $query->updateAttributes = $onConflict->getOnConflictUpdateValues();
×
40
                $query->upsertConflictColumns = $onConflict->getOnConflictColumns();
×
41
                $this->query = $query;
×
42
                $sql .= $this->onConflictUpdate();
×
43
            }
44
        }
45

46
        if ($primaryKey) {
×
47
            return "{$sql} RETURNING {$primaryKey}";
×
48
        }
49
        return $sql;
×
50
    }
51

52
    protected function insertEmptyRow(): string
53
    {
54
        return "INSERT INTO {$this->query->table} DEFAULT VALUES";
×
55
    }
56

57
    public function regexpMatcher(): string
58
    {
59
        return '~';
1✔
60
    }
61

62
    protected function quote(string $word): string
63
    {
64
        return "\"{$word}\"";
×
65
    }
66

67
    public function onConflictUpdate(): string
68
    {
69
        $attributes = DialectUtil::buildAttributesPartForUpdate($this->query->updateAttributes);
1✔
70
        $upsertConflictColumns = $this->query->upsertConflictColumns;
1✔
71
        $joinedColumns = implode(', ', $upsertConflictColumns);
1✔
72
        return " ON CONFLICT ({$joinedColumns}) DO UPDATE SET {$attributes}";
1✔
73
    }
74

75
    public function onConflictDoNothing(): string
76
    {
77
        return " ON CONFLICT DO NOTHING";
×
78
    }
79

80
    protected function getDistinctOnQuery(): string
81
    {
82
        return 'DISTINCT ON (' . Joiner::on(', ')->join($this->query->distinctOnColumns) . ') ';
2✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc