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

letsdrink / ouzo / 7531968351

15 Jan 2024 05:00PM UTC coverage: 86.005% (+0.002%) from 86.003%
7531968351

push

github

bbankowski
Reverted StreamStub changes. Fixed the problem by not invoking `stream_get_contents` when it is not needed.

9 of 10 new or added lines in 1 file covered. (90.0%)

86 existing lines in 9 files now uncovered.

4984 of 5795 relevant lines covered (86.01%)

101.41 hits per line

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

96.43
/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'];
8✔
19
    }
20

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

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

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

UNCOV
46
        if ($primaryKey) {
5✔
UNCOV
47
            return "{$sql} RETURNING {$primaryKey}";
2✔
48
        }
UNCOV
49
        return $sql;
3✔
50
    }
51

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

57
    public function regexpMatcher(): string
58
    {
59
        return '~';
4✔
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);
8✔
70
        $upsertConflictColumns = $this->query->upsertConflictColumns;
8✔
71
        $joinedColumns = implode(', ', $upsertConflictColumns);
8✔
72
        return " ON CONFLICT ({$joinedColumns}) DO UPDATE SET {$attributes}";
8✔
73
    }
74

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

80
    protected function getDistinctOnQuery(): string
81
    {
82
        return 'DISTINCT ON (' . Joiner::on(', ')->join($this->query->distinctOnColumns) . ') ';
10✔
83
    }
84

85
    protected function wrapQueryWithDistinctCount(string $sql): string
86
    {
87
        return "SELECT count(*) FROM ({$sql}) AS count_data";
3✔
88
    }
89
}
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