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

letsdrink / ouzo / 6036930958

31 Aug 2023 11:53AM UTC coverage: 82.907% (-3.1%) from 86.01%
6036930958

push

github

web-flow
Add string space const (#318)

4802 of 5792 relevant lines covered (82.91%)

32.99 hits per line

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

32.14
/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
    {
28
        $valueClause = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')';
5✔
29
        $valueClauses = implode(', ', array_fill(0, $batchSize, $valueClause));
5✔
30
        $joinedColumns = implode(', ', $columns);
5✔
31
        $sql = "INSERT INTO {$table} ($joinedColumns) VALUES $valueClauses";
5✔
32

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

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

52
    protected function insertEmptyRow(): string
53
    {
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
    {
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