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

hyperledger-labs / fabric-token-sdk / 26328106246

23 May 2026 08:27AM UTC coverage: 82.523% (-0.08%) from 82.604%
26328106246

Pull #1729

github

web-flow
Merge baaad356b into bfc8bf728
Pull Request #1729: feat(auditor): extract Locker interface with pluggable distributed locking

365 of 478 new or added lines in 19 files covered. (76.36%)

1 existing line in 1 file now uncovered.

36047 of 43681 relevant lines covered (82.52%)

17.3 hits per line

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

93.64
/token/services/storage/db/sql/query/insert/query.go
1
/*
2
Copyright IBM Corp. All Rights Reserved.
3

4
SPDX-License-Identifier: Apache-2.0
5
*/
6

7
package _insert
8

9
import (
10
        "time"
11

12
        common2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/storage/db/sql/query/common"
13
        cond2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/storage/db/sql/query/cond"
14
)
15

16
type query struct {
17
        table          common2.TableName
18
        fields         []common2.FieldName
19
        rows           []common2.Tuple
20
        valueRows      [][]common2.Serializable
21
        boundPrefix    []common2.Param
22
        conflictFields []common2.FieldName
23
        onConflicts    []OnConflict
24
        conflictWhere  cond2.Condition
25
        returning      []common2.FieldName
26
        ignoreConflict bool
27
}
28

29
func NewQuery() *query {
55✔
30
        return &query{}
55✔
31
}
55✔
32

33
func (q *query) Into(table common2.TableName) Query {
55✔
34
        q.table = table
55✔
35

55✔
36
        return q
55✔
37
}
55✔
38

39
func (q *query) Fields(fields ...common2.FieldName) fieldsQuery {
55✔
40
        q.fields = fields
55✔
41

55✔
42
        return q
55✔
43
}
55✔
44

45
func (q *query) Row(tuple ...common2.Param) fieldsQuery {
53✔
46
        if len(tuple) != len(q.fields) {
53✔
47
                panic("wrong length")
×
48
        }
49
        q.rows = append(q.rows, tuple)
53✔
50

53✔
51
        return q
53✔
52
}
53

54
func (q *query) Rows(tuples []common2.Tuple) fieldsQuery {
47✔
55
        for _, tuple := range tuples {
94✔
56
                q.Row(tuple...)
47✔
57
        }
47✔
58

59
        return q
47✔
60
}
61

62
func (q *query) RowValues(cells ...common2.Serializable) fieldsQuery {
4✔
63
        if len(cells) != len(q.fields) {
4✔
NEW
64
                panic("wrong length")
×
65
        }
66
        q.valueRows = append(q.valueRows, cells)
4✔
67

4✔
68
        return q
4✔
69
}
70

71
func (q *query) WithBoundParams(params ...common2.Param) fieldsQuery {
4✔
72
        q.boundPrefix = append(q.boundPrefix, params...)
4✔
73

4✔
74
        return q
4✔
75
}
4✔
76

77
func (q *query) OnConflict(fields []common2.FieldName, onConflicts ...OnConflict) onConflictQuery {
4✔
78
        if len(onConflicts) == 0 {
4✔
79
                panic("no strategy passed")
×
80
        }
81
        q.conflictFields = fields
4✔
82
        q.onConflicts = onConflicts
4✔
83

4✔
84
        return q
4✔
85
}
86

87
func (q *query) OnConflictDoNothing() onConflictQuery {
47✔
88
        q.ignoreConflict = true
47✔
89

47✔
90
        return q
47✔
91
}
47✔
92

93
func (q *query) Where(where cond2.Condition) onConflictQuery {
2✔
94
        q.conflictWhere = where
2✔
95

2✔
96
        return q
2✔
97
}
2✔
98

99
func (q *query) Returning(fields ...common2.FieldName) onConflictQuery {
4✔
100
        q.returning = fields
4✔
101

4✔
102
        return q
4✔
103
}
4✔
104

105
func (q *query) Format() (string, []common2.Param) {
55✔
106
        sb := common2.NewBuilder()
55✔
107
        q.FormatTo(sb)
55✔
108

55✔
109
        return sb.Build()
55✔
110
}
55✔
111

112
func (q *query) FormatTo(sb common2.Builder) {
55✔
113
        sb.WriteString("INSERT INTO ").
55✔
114
                WriteString(string(q.table)).
55✔
115
                WriteString(" (").
55✔
116
                WriteSerializables(common2.ToSerializables(q.fields)...).
55✔
117
                WriteString(") VALUES ")
55✔
118

55✔
119
        if len(q.boundPrefix) > 0 {
59✔
120
                sb.BindParams(q.boundPrefix...)
4✔
121
        }
4✔
122

123
        switch {
55✔
124
        case len(q.valueRows) > 0:
4✔
125
                sb.WriteValueTuples(q.valueRows)
4✔
126
        case len(q.rows) > 0:
53✔
127
                sb.WriteTuples(q.rows)
53✔
NEW
128
        default:
×
NEW
129
                panic("no rows to insert")
×
130
        }
131

132
        if q.ignoreConflict {
102✔
133
                sb.WriteString(" ON CONFLICT DO NOTHING")
47✔
134
                q.writeReturning(sb)
47✔
135

47✔
136
                return
47✔
137
        }
47✔
138
        if q.conflictFields != nil {
59✔
139
                sb.WriteString(" ON CONFLICT (").
4✔
140
                        WriteSerializables(common2.ToSerializables(q.conflictFields)...).
4✔
141
                        WriteString(") DO UPDATE SET ").
4✔
142
                        WriteSerializables(common2.ToSerializables(q.onConflicts)...)
4✔
143
                if q.conflictWhere != nil && q.conflictWhere != cond2.AlwaysTrue {
6✔
144
                        sb.WriteString(" WHERE ")
2✔
145
                        // conflict WHERE uses table-qualified fields; no interpreter needed for InPast/Excluded.
2✔
146
                        sb.WriteConditionSerializable(q.conflictWhere, nilInterpreter{})
2✔
147
                }
2✔
148
        }
149
        q.writeReturning(sb)
55✔
150
}
151

152
type nilInterpreter struct{}
153

154
func (nilInterpreter) TimeOffset(duration time.Duration, sb common2.Builder) {
2✔
155
        sb.WriteString("NOW()")
2✔
156
        if duration == 0 {
4✔
157
                return
2✔
158
        }
2✔
NEW
159
        panic("unsupported duration in insert ON CONFLICT WHERE")
×
160
}
161

NEW
162
func (nilInterpreter) InTuple(_ []common2.Serializable, _ []common2.Tuple, _ common2.Builder) {}
×
163

164
func (q *query) writeReturning(sb common2.Builder) {
55✔
165
        if len(q.returning) == 0 {
108✔
166
                return
53✔
167
        }
53✔
168
        sb.WriteString(" RETURNING ").
4✔
169
                WriteSerializables(common2.ToSerializables(q.returning)...)
4✔
170
}
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