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

torand / FasterSQL / 15294773771

28 May 2025 08:01AM UTC coverage: 70.078% (+0.2%) from 69.877%
15294773771

Pull #31

github

web-flow
Merge 9f1c324c0 into 6be86da23
Pull Request #31: feat: add support for SQLite dialect

233 of 418 branches covered (55.74%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 12 files covered. (84.85%)

45 existing lines in 10 files now uncovered.

1212 of 1644 relevant lines covered (73.72%)

3.91 hits per line

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

77.78
/src/main/java/io/github/torand/fastersql/dialect/PostgreSqlDialect.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.dialect;
17

18
import java.util.EnumSet;
19
import java.util.List;
20
import java.util.Optional;
21

22
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
23
import static io.github.torand.fastersql.dialect.Capability.CURRENT_TIME;
24
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
25
import static io.github.torand.fastersql.dialect.Capability.MODULO_OPERATOR;
26
import static io.github.torand.fastersql.dialect.Capability.NULL_ORDERING;
27
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
28
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
29
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
30

31
/**
32
 * Defines the PostgreSQL SQL dialect
33
 *
34
 * <a href="https://www.postgresql.org/docs/current/" />
35
 */
36
public class PostgreSqlDialect implements Dialect {
3✔
37
    private static final EnumSet<Capability> SUPPORTED_CAPS = EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, MODULO_OPERATOR, CURRENT_TIME, NULL_ORDERING, SELECT_FOR_UPDATE, TRUNCATE_TABLE);
30✔
38

39
    @Override
40
    public String getProductName() {
41
        return "PostgreSQL";
2✔
42
    }
43

44
    @Override
45
    public boolean offsetBeforeLimit() {
46
        return true;
2✔
47
    }
48

49
    @Override
50
    public Optional<String> formatRowOffsetClause() {
51
        return Optional.of("offset ?");
3✔
52
    }
53

54
    @Override
55
    public Optional<String> formatRowLimitClause() {
56
        return Optional.of("limit ?");
3✔
57
    }
58

59
    @Override
60
    public Optional<String> formatRowNumLiteral() {
UNCOV
61
        return Optional.empty();
×
62
    }
63

64
    @Override
65
    public String formatToNumberFunction(String operand, int precision, int scale) {
66
        StringBuilder mask = new StringBuilder();
4✔
67
        if (precision-scale > 0) {
4!
68
            mask.append(generate("9", precision-scale));
8✔
69
        }
70
        if (scale > 0) {
2!
UNCOV
71
            mask.append(".").append(generate("9", scale));
×
72
        }
73

74
        return "to_number(" + operand + ", '" + mask + "')";
5✔
75
    }
76

77
    @Override
78
    public String formatToCharFunction(String operand, String format) {
79
        return "to_char(" + operand + ", " + format + ")";
4✔
80
    }
81

82
    @Override
83
    public String formatSubstringFunction(String operand, int startPos, int length) {
84
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
85
    }
86

87
    @Override
88
    public String formatConcatFunction(List<String> operands) {
UNCOV
89
        throw new UnsupportedOperationException("PostgreSQL does not support the concat() function (use the concat infix operator instead)");
×
90
    }
91

92
    @Override
93
    public String formatLengthFunction(String operand) {
94
        return "char_length(" + operand + ")";
3✔
95
    }
96

97
    @Override
98
    public String formatCeilFunction(String operand) {
99
        return "ceil(" + operand + ")";
3✔
100
    }
101

102
    @Override
103
    public String formatRoundFunction(String operand) {
104
        return "round(" + operand + ")";
3✔
105
    }
106

107
    @Override
108
    public String formatModuloFunction(String divisor, String dividend) {
UNCOV
109
        throw new UnsupportedOperationException("PostgreSQL does not support the mod() function (use the modulo infix operator instead)");
×
110
    }
111

112
    @Override
113
    public String formatCurrentDateFunction() {
114
        return "current_date";
2✔
115
    }
116

117
    @Override
118
    public Optional<String> getConcatOperator() {
119
        return Optional.of("||");
3✔
120
    }
121

122
    @Override
123
    public boolean supports(Capability capability) {
124
        return SUPPORTED_CAPS.contains(capability);
4✔
125
    }
126
}
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