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

torand / FasterSQL / 12970217277

26 Jan 2025 01:31AM UTC coverage: 49.458%. Remained the same
12970217277

push

github

torand
refactor: condition -> predicate

108 of 322 branches covered (33.54%)

Branch coverage included in aggregate %.

58 of 137 new or added lines in 12 files covered. (42.34%)

3 existing lines in 2 files now uncovered.

622 of 1154 relevant lines covered (53.9%)

2.85 hits per line

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

65.52
/src/main/java/io/github/torand/fastersql/Field.java
1
/*
2
 * Copyright (c) 2024 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;
17

18
import io.github.torand.fastersql.expression.Expression;
19
import io.github.torand.fastersql.order.Order;
20
import io.github.torand.fastersql.order.Orders;
21
import io.github.torand.fastersql.predicate.LeftOperand;
22
import io.github.torand.fastersql.predicate.Predicate;
23
import io.github.torand.fastersql.predicate.Predicates;
24
import io.github.torand.fastersql.projection.Projection;
25

26
import java.util.stream.Stream;
27

28
import static io.github.torand.fastersql.Command.SELECT;
29
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
30
import static java.util.Objects.requireNonNull;
31

32
public class Field implements Projection, LeftOperand, Expression {
33
    private final Table<?> table;
34
    private final String name;
35
    private final String alias;
36

37
    public Field(Table<?> table, String name) {
2✔
38
        this.table = requireNonNull(table, "No table specified");
6✔
39
        this.name = requireNonBlank(name, "No name specified");
7✔
40
        this.alias = defaultAlias(table, name);
6✔
41
    }
1✔
42

43
    private Field(Table<?> table, String name, String alias) {
×
44
        this.table = requireNonNull(table, "No table specified");
×
45
        this.name = requireNonBlank(name, "No name specified");
×
46
        this.alias = requireNonBlank(alias, "No alias specified");
×
47
    }
×
48

49
    // Sql
50

51
    @Override
52
    public String sql(Context context) {
53
        if (context.isCommand(SELECT)) {
4✔
54
            return table.alias() + "." + name;
7✔
55
        } else {
56
            return name;
3✔
57
        }
58
    }
59

60
    @Override
61
    public Stream<Object> params(Context context) {
62
        return Stream.empty();
2✔
63
    }
64

65
    // Projection
66

67
    @Override
68
    public Projection as(String alias) {
69
        return new Field(table, name, alias);
×
70
    }
71

72
    @Override
73
    public String alias() {
74
        return alias;
3✔
75
    }
76

77
    // LeftOperand / Expression
78

79
    @Override
80
    public Stream<Field> fieldRefs() {
81
        return Stream.of(this);
3✔
82
    }
83

84
    public Predicate isNull() {
85
        return Predicates.isNull(this);
3✔
86
    }
87

88
    public Join on(Field other) {
89
        return new Join(this, other);
6✔
90
    }
91

92
    public Order asc() {
93
        return Orders.asc(this);
3✔
94
    }
95

96
    public Order ascIf(boolean condition) {
NEW
97
        return condition ? asc() : desc();
×
98
    }
99

100
    public Order desc() {
101
        return Orders.desc(this);
3✔
102
    }
103

104
    public String name() {
105
        return name;
×
106
    }
107

108
    public Table<?> table() {
109
        return table;
3✔
110
    }
111

112
    private String defaultAlias(Table<?> table, String name) {
113
        return (table.alias() + "_" + name).toUpperCase();
6✔
114
    }
115
}
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