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

torand / FasterSQL / 12893661530

21 Jan 2025 06:40PM UTC coverage: 50.829%. Remained the same
12893661530

push

github

torand
refactor: rename expression -> condition

104 of 304 branches covered (34.21%)

Branch coverage included in aggregate %.

81 of 211 new or added lines in 24 files covered. (38.39%)

3 existing lines in 2 files now uncovered.

601 of 1083 relevant lines covered (55.49%)

2.91 hits per line

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

64.29
/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.condition.Condition;
19
import io.github.torand.fastersql.condition.LeftOperand;
20
import io.github.torand.fastersql.condition.comparison.ComparisonConditions;
21
import io.github.torand.fastersql.order.Order;
22
import io.github.torand.fastersql.order.Orders;
23
import io.github.torand.fastersql.projection.Projection;
24

25
import java.util.stream.Stream;
26

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

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

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

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

48
    @Override
49
    public Projection as(String alias) {
50
        return new Field(table, name, alias);
×
51
    }
52

53
    @Override
54
    public Stream<Field> fields() {
55
        return Stream.of(this);
3✔
56
    }
57

58
    public Condition isNull() {
59
        return ComparisonConditions.isNull(this);
3✔
60
    }
61

62
    public Join on(Field other) {
63
        return new Join(this, other);
6✔
64
    }
65

66
    public Order asc() {
67
        return Orders.asc(this);
3✔
68
    }
69

70
    public Order ascIf(boolean predicate) {
NEW
71
        return predicate ? asc() : desc();
×
72
    }
73

74
    public Order desc() {
75
        return Orders.desc(this);
3✔
76
    }
77

78
    public String name() {
79
        return name;
×
80
    }
81

82
    @Override
83
    public String alias() {
84
        return alias;
3✔
85
    }
86

87
    public Table<?> table() {
88
        return table;
3✔
89
    }
90

91
    @Override
92
    public String sql(Context context) {
93
        if (context.isCommand(SELECT)) {
4✔
94
            return table.alias() + "." + name;
7✔
95
        } else {
96
            return name;
3✔
97
        }
98
    }
99

100
    private String defaultAlias(Table<?> table, String name) {
101
        return (table.alias() + "_" + name).toUpperCase();
6✔
102
    }
103
}
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