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

lightningnetwork / lnd / 15602248895

12 Jun 2025 05:17AM UTC coverage: 68.413% (+10.1%) from 58.333%
15602248895

Pull #9887

github

web-flow
Merge b1e8fe5d9 into 35102e7c3
Pull Request #9887: graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD

0 of 262 new or added lines in 2 files covered. (0.0%)

29 existing lines in 7 files now uncovered.

134436 of 196507 relevant lines covered (68.41%)

22270.16 hits per line

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

0.0
/sqldb/sqlc/graph.sql.go
1
// Code generated by sqlc. DO NOT EDIT.
2
// versions:
3
//   sqlc v1.29.0
4
// source: graph.sql
5

6
package sqlc
7

8
import (
9
        "context"
10
        "database/sql"
11
)
12

13
const addSourceNode = `-- name: AddSourceNode :exec
14
/* ─────────────────────────────────────────────
15
   source_nodes table queries
16
   ─────────────────────────────────────────────
17
*/
18

19
INSERT INTO source_nodes (node_id)
20
VALUES ($1)
21
ON CONFLICT (node_id) DO NOTHING
22
`
23

24
func (q *Queries) AddSourceNode(ctx context.Context, nodeID int64) error {
×
25
        _, err := q.db.ExecContext(ctx, addSourceNode, nodeID)
×
26
        return err
×
27
}
×
28

29
const createChannel = `-- name: CreateChannel :one
30
/* ─────────────────────────────────────────────
31
   channels table queries
32
   ─────────────────────────────────────────────
33
*/
34

35
INSERT INTO channels (
36
    version, scid, node_id_1, node_id_2,
37
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
38
    node_1_signature, node_2_signature, bitcoin_1_signature,
39
    bitcoin_2_signature
40
) VALUES (
41
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
42
)
43
RETURNING id
44
`
45

46
type CreateChannelParams struct {
47
        Version           int16
48
        Scid              []byte
49
        NodeID1           int64
50
        NodeID2           int64
51
        Outpoint          string
52
        Capacity          sql.NullInt64
53
        BitcoinKey1       []byte
54
        BitcoinKey2       []byte
55
        Node1Signature    []byte
56
        Node2Signature    []byte
57
        Bitcoin1Signature []byte
58
        Bitcoin2Signature []byte
59
}
60

61
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
62
        row := q.db.QueryRowContext(ctx, createChannel,
×
63
                arg.Version,
×
64
                arg.Scid,
×
65
                arg.NodeID1,
×
66
                arg.NodeID2,
×
67
                arg.Outpoint,
×
68
                arg.Capacity,
×
69
                arg.BitcoinKey1,
×
70
                arg.BitcoinKey2,
×
71
                arg.Node1Signature,
×
72
                arg.Node2Signature,
×
73
                arg.Bitcoin1Signature,
×
74
                arg.Bitcoin2Signature,
×
75
        )
×
76
        var id int64
×
77
        err := row.Scan(&id)
×
78
        return id, err
×
79
}
×
80

81
const createChannelExtraType = `-- name: CreateChannelExtraType :exec
82
/* ─────────────────────────────────────────────
83
   channel_extra_types table queries
84
   ─────────────────────────────────────────────
85
*/
86

87
INSERT INTO channel_extra_types (
88
    channel_id, type, value
89
)
90
VALUES ($1, $2, $3)
91
`
92

93
type CreateChannelExtraTypeParams struct {
94
        ChannelID int64
95
        Type      int64
96
        Value     []byte
97
}
98

99
func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error {
×
100
        _, err := q.db.ExecContext(ctx, createChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
101
        return err
×
102
}
×
103

104
const deleteChannelPolicyExtraType = `-- name: DeleteChannelPolicyExtraType :exec
105
DELETE FROM channel_policy_extra_types
106
WHERE channel_policy_id = $1
107
  AND type = $2
108
`
109

110
type DeleteChannelPolicyExtraTypeParams struct {
111
        ChannelPolicyID int64
112
        Type            int64
113
}
114

NEW
115
func (q *Queries) DeleteChannelPolicyExtraType(ctx context.Context, arg DeleteChannelPolicyExtraTypeParams) error {
×
NEW
116
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraType, arg.ChannelPolicyID, arg.Type)
×
NEW
117
        return err
×
NEW
118
}
×
119

120
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
121
DELETE FROM node_extra_types
122
WHERE node_id = $1
123
  AND type = $2
124
`
125

126
type DeleteExtraNodeTypeParams struct {
127
        NodeID int64
128
        Type   int64
129
}
130

131
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
132
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
133
        return err
×
134
}
×
135

136
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
137
DELETE FROM node_addresses
138
WHERE node_id = $1
139
`
140

141
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
142
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
143
        return err
×
144
}
×
145

146
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
147
DELETE FROM nodes
148
WHERE pub_key = $1
149
  AND version = $2
150
`
151

152
type DeleteNodeByPubKeyParams struct {
153
        PubKey  []byte
154
        Version int16
155
}
156

157
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
158
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
159
}
×
160

161
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
162
DELETE FROM node_features
163
WHERE node_id = $1
164
  AND feature_bit = $2
165
`
166

167
type DeleteNodeFeatureParams struct {
168
        NodeID     int64
169
        FeatureBit int32
170
}
171

172
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
173
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
174
        return err
×
175
}
×
176

177
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
178
SELECT
179
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
180
    n1.pub_key AS node1_pub_key,
181
    n2.pub_key AS node2_pub_key
182
FROM channels c
183
    JOIN nodes n1 ON c.node_id_1 = n1.id
184
    JOIN nodes n2 ON c.node_id_2 = n2.id
185
WHERE c.scid = $1
186
  AND c.version = $2
187
`
188

189
type GetChannelAndNodesBySCIDParams struct {
190
        Scid    []byte
191
        Version int16
192
}
193

194
type GetChannelAndNodesBySCIDRow struct {
195
        ID                int64
196
        Version           int16
197
        Scid              []byte
198
        NodeID1           int64
199
        NodeID2           int64
200
        Outpoint          string
201
        Capacity          sql.NullInt64
202
        BitcoinKey1       []byte
203
        BitcoinKey2       []byte
204
        Node1Signature    []byte
205
        Node2Signature    []byte
206
        Bitcoin1Signature []byte
207
        Bitcoin2Signature []byte
208
        Node1PubKey       []byte
209
        Node2PubKey       []byte
210
}
211

NEW
212
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
NEW
213
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
NEW
214
        var i GetChannelAndNodesBySCIDRow
×
NEW
215
        err := row.Scan(
×
NEW
216
                &i.ID,
×
NEW
217
                &i.Version,
×
NEW
218
                &i.Scid,
×
NEW
219
                &i.NodeID1,
×
NEW
220
                &i.NodeID2,
×
NEW
221
                &i.Outpoint,
×
NEW
222
                &i.Capacity,
×
NEW
223
                &i.BitcoinKey1,
×
NEW
224
                &i.BitcoinKey2,
×
NEW
225
                &i.Node1Signature,
×
NEW
226
                &i.Node2Signature,
×
NEW
227
                &i.Bitcoin1Signature,
×
NEW
228
                &i.Bitcoin2Signature,
×
NEW
229
                &i.Node1PubKey,
×
NEW
230
                &i.Node2PubKey,
×
NEW
231
        )
×
NEW
232
        return i, err
×
NEW
233
}
×
234

235
const getChannelBySCID = `-- name: GetChannelBySCID :one
236
SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM channels
237
WHERE scid = $1 AND version = $2
238
`
239

240
type GetChannelBySCIDParams struct {
241
        Scid    []byte
242
        Version int16
243
}
244

245
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
246
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
247
        var i Channel
×
248
        err := row.Scan(
×
249
                &i.ID,
×
250
                &i.Version,
×
251
                &i.Scid,
×
252
                &i.NodeID1,
×
253
                &i.NodeID2,
×
254
                &i.Outpoint,
×
255
                &i.Capacity,
×
256
                &i.BitcoinKey1,
×
257
                &i.BitcoinKey2,
×
258
                &i.Node1Signature,
×
259
                &i.Node2Signature,
×
260
                &i.Bitcoin1Signature,
×
261
                &i.Bitcoin2Signature,
×
262
        )
×
263
        return i, err
×
264
}
×
265

266
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
267
SELECT
268
    cp.id AS policy_id,
269
    cp.channel_id,
270
    cp.node_id,
271
    cpet.type,
272
    cpet.value
273
FROM channel_policies cp
274
JOIN channel_policy_extra_types cpet
275
ON cp.id = cpet.channel_policy_id
276
WHERE cp.id = $1 OR cp.id = $2
277
`
278

279
type GetChannelPolicyExtraTypesParams struct {
280
        ID   int64
281
        ID_2 int64
282
}
283

284
type GetChannelPolicyExtraTypesRow struct {
285
        PolicyID  int64
286
        ChannelID int64
287
        NodeID    int64
288
        Type      int64
289
        Value     []byte
290
}
291

NEW
292
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
NEW
293
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
NEW
294
        if err != nil {
×
NEW
295
                return nil, err
×
NEW
296
        }
×
NEW
297
        defer rows.Close()
×
NEW
298
        var items []GetChannelPolicyExtraTypesRow
×
NEW
299
        for rows.Next() {
×
NEW
300
                var i GetChannelPolicyExtraTypesRow
×
NEW
301
                if err := rows.Scan(
×
NEW
302
                        &i.PolicyID,
×
NEW
303
                        &i.ChannelID,
×
NEW
304
                        &i.NodeID,
×
NEW
305
                        &i.Type,
×
NEW
306
                        &i.Value,
×
NEW
307
                ); err != nil {
×
NEW
308
                        return nil, err
×
NEW
309
                }
×
NEW
310
                items = append(items, i)
×
311
        }
NEW
312
        if err := rows.Close(); err != nil {
×
NEW
313
                return nil, err
×
NEW
314
        }
×
NEW
315
        if err := rows.Err(); err != nil {
×
NEW
316
                return nil, err
×
NEW
317
        }
×
NEW
318
        return items, nil
×
319
}
320

321
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
322
SELECT node_id, type, value
323
FROM node_extra_types
324
WHERE node_id = $1
325
`
326

327
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
328
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
329
        if err != nil {
×
330
                return nil, err
×
331
        }
×
332
        defer rows.Close()
×
333
        var items []NodeExtraType
×
334
        for rows.Next() {
×
335
                var i NodeExtraType
×
336
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
337
                        return nil, err
×
338
                }
×
339
                items = append(items, i)
×
340
        }
341
        if err := rows.Close(); err != nil {
×
342
                return nil, err
×
343
        }
×
344
        if err := rows.Err(); err != nil {
×
345
                return nil, err
×
346
        }
×
347
        return items, nil
×
348
}
349

350
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
351
SELECT a.type, a.address
352
FROM nodes n
353
LEFT JOIN node_addresses a ON a.node_id = n.id
354
WHERE n.pub_key = $1 AND n.version = $2
355
ORDER BY a.type ASC, a.position ASC
356
`
357

358
type GetNodeAddressesByPubKeyParams struct {
359
        PubKey  []byte
360
        Version int16
361
}
362

363
type GetNodeAddressesByPubKeyRow struct {
364
        Type    sql.NullInt16
365
        Address sql.NullString
366
}
367

368
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
369
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
370
        if err != nil {
×
371
                return nil, err
×
372
        }
×
373
        defer rows.Close()
×
374
        var items []GetNodeAddressesByPubKeyRow
×
375
        for rows.Next() {
×
376
                var i GetNodeAddressesByPubKeyRow
×
377
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
378
                        return nil, err
×
379
                }
×
380
                items = append(items, i)
×
381
        }
382
        if err := rows.Close(); err != nil {
×
383
                return nil, err
×
384
        }
×
385
        if err := rows.Err(); err != nil {
×
386
                return nil, err
×
387
        }
×
388
        return items, nil
×
389
}
390

391
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
392
SELECT id, version, pub_key, alias, last_update, color, signature
393
FROM nodes
394
WHERE pub_key = $1
395
  AND version = $2
396
`
397

398
type GetNodeByPubKeyParams struct {
399
        PubKey  []byte
400
        Version int16
401
}
402

403
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
404
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
405
        var i Node
×
406
        err := row.Scan(
×
407
                &i.ID,
×
408
                &i.Version,
×
409
                &i.PubKey,
×
410
                &i.Alias,
×
411
                &i.LastUpdate,
×
412
                &i.Color,
×
413
                &i.Signature,
×
414
        )
×
415
        return i, err
×
416
}
×
417

418
const getNodeFeatures = `-- name: GetNodeFeatures :many
419
SELECT node_id, feature_bit
420
FROM node_features
421
WHERE node_id = $1
422
`
423

424
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
425
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
426
        if err != nil {
×
427
                return nil, err
×
428
        }
×
429
        defer rows.Close()
×
430
        var items []NodeFeature
×
431
        for rows.Next() {
×
432
                var i NodeFeature
×
433
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
434
                        return nil, err
×
435
                }
×
436
                items = append(items, i)
×
437
        }
438
        if err := rows.Close(); err != nil {
×
439
                return nil, err
×
440
        }
×
441
        if err := rows.Err(); err != nil {
×
442
                return nil, err
×
443
        }
×
444
        return items, nil
×
445
}
446

447
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
448
SELECT f.feature_bit
449
FROM nodes n
450
    JOIN node_features f ON f.node_id = n.id
451
WHERE n.pub_key = $1
452
  AND n.version = $2
453
`
454

455
type GetNodeFeaturesByPubKeyParams struct {
456
        PubKey  []byte
457
        Version int16
458
}
459

460
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
461
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
462
        if err != nil {
×
463
                return nil, err
×
464
        }
×
465
        defer rows.Close()
×
466
        var items []int32
×
467
        for rows.Next() {
×
468
                var feature_bit int32
×
469
                if err := rows.Scan(&feature_bit); err != nil {
×
470
                        return nil, err
×
471
                }
×
472
                items = append(items, feature_bit)
×
473
        }
474
        if err := rows.Close(); err != nil {
×
475
                return nil, err
×
476
        }
×
477
        if err := rows.Err(); err != nil {
×
478
                return nil, err
×
479
        }
×
480
        return items, nil
×
481
}
482

483
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
484
SELECT id, version, pub_key, alias, last_update, color, signature
485
FROM nodes
486
WHERE last_update >= $1
487
  AND last_update < $2
488
`
489

490
type GetNodesByLastUpdateRangeParams struct {
491
        StartTime sql.NullInt64
492
        EndTime   sql.NullInt64
493
}
494

495
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
496
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
497
        if err != nil {
×
498
                return nil, err
×
499
        }
×
500
        defer rows.Close()
×
501
        var items []Node
×
502
        for rows.Next() {
×
503
                var i Node
×
504
                if err := rows.Scan(
×
505
                        &i.ID,
×
506
                        &i.Version,
×
507
                        &i.PubKey,
×
508
                        &i.Alias,
×
509
                        &i.LastUpdate,
×
510
                        &i.Color,
×
511
                        &i.Signature,
×
512
                ); err != nil {
×
513
                        return nil, err
×
514
                }
×
515
                items = append(items, i)
×
516
        }
517
        if err := rows.Close(); err != nil {
×
518
                return nil, err
×
519
        }
×
520
        if err := rows.Err(); err != nil {
×
521
                return nil, err
×
522
        }
×
523
        return items, nil
×
524
}
525

526
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
527
SELECT sn.node_id, n.pub_key
528
FROM source_nodes sn
529
    JOIN nodes n ON sn.node_id = n.id
530
WHERE n.version = $1
531
`
532

533
type GetSourceNodesByVersionRow struct {
534
        NodeID int64
535
        PubKey []byte
536
}
537

538
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
539
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
540
        if err != nil {
×
541
                return nil, err
×
542
        }
×
543
        defer rows.Close()
×
544
        var items []GetSourceNodesByVersionRow
×
545
        for rows.Next() {
×
546
                var i GetSourceNodesByVersionRow
×
547
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
548
                        return nil, err
×
549
                }
×
550
                items = append(items, i)
×
551
        }
552
        if err := rows.Close(); err != nil {
×
553
                return nil, err
×
554
        }
×
555
        if err := rows.Err(); err != nil {
×
556
                return nil, err
×
557
        }
×
558
        return items, nil
×
559
}
560

561
const highestSCID = `-- name: HighestSCID :one
562
SELECT scid
563
FROM channels
564
WHERE version = $1
565
ORDER BY scid DESC
566
LIMIT 1
567
`
568

569
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
570
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
571
        var scid []byte
×
572
        err := row.Scan(&scid)
×
573
        return scid, err
×
574
}
×
575

576
const insertChannelFeature = `-- name: InsertChannelFeature :exec
577
/* ─────────────────────────────────────────────
578
   channel_features table queries
579
   ─────────────────────────────────────────────
580
*/
581

582
INSERT INTO channel_features (
583
    channel_id, feature_bit
584
) VALUES (
585
    $1, $2
586
)
587
`
588

589
type InsertChannelFeatureParams struct {
590
        ChannelID  int64
591
        FeatureBit int32
592
}
593

594
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
595
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
596
        return err
×
597
}
×
598

599
const insertNodeAddress = `-- name: InsertNodeAddress :exec
600
/* ─────────────────────────────────────────────
601
   node_addresses table queries
602
   ─────────────────────────────────────────────
603
*/
604

605
INSERT INTO node_addresses (
606
    node_id,
607
    type,
608
    address,
609
    position
610
) VALUES (
611
    $1, $2, $3, $4
612
 )
613
`
614

615
type InsertNodeAddressParams struct {
616
        NodeID   int64
617
        Type     int16
618
        Address  string
619
        Position int32
620
}
621

622
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
623
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
624
                arg.NodeID,
×
625
                arg.Type,
×
626
                arg.Address,
×
627
                arg.Position,
×
628
        )
×
629
        return err
×
630
}
×
631

632
const insertNodeFeature = `-- name: InsertNodeFeature :exec
633
/* ─────────────────────────────────────────────
634
   node_features table queries
635
   ─────────────────────────────────────────────
636
*/
637

638
INSERT INTO node_features (
639
    node_id, feature_bit
640
) VALUES (
641
    $1, $2
642
)
643
`
644

645
type InsertNodeFeatureParams struct {
646
        NodeID     int64
647
        FeatureBit int32
648
}
649

650
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
651
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
652
        return err
×
653
}
×
654

655
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
656
/* ─────────────────────────────────────────────
657
   channel_policy_extra_types table queries
658
   ─────────────────────────────────────────────
659
*/
660

661
INSERT INTO channel_policy_extra_types (
662
    channel_policy_id, type, value
663
)
664
VALUES ($1, $2, $3)
665
ON CONFLICT (type, channel_policy_id)
666
    -- Update the value if a conflict occurs on type
667
    -- and node_id.
668
    DO UPDATE SET value = EXCLUDED.value
669
`
670

671
type UpsertChanPolicyExtraTypeParams struct {
672
        ChannelPolicyID int64
673
        Type            int64
674
        Value           []byte
675
}
676

NEW
677
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
NEW
678
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
NEW
679
        return err
×
NEW
680
}
×
681

682
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
683
/* ─────────────────────────────────────────────
684
   channel_policies table queries
685
   ─────────────────────────────────────────────
686
*/
687

688
INSERT INTO channel_policies (
689
    version, channel_id, node_id, timelock, fee_ppm,
690
    base_fee_msat, min_htlc_msat, last_update, disabled,
691
    max_htlc_msat, inbound_base_fee_msat,
692
    inbound_fee_rate_milli_msat, signature
693
) VALUES  (
694
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
695
)
696
ON CONFLICT (channel_id, node_id, version)
697
    -- Update the following fields if a conflict occurs on channel_id,
698
    -- node_id, and version.
699
    DO UPDATE SET
700
        timelock = EXCLUDED.timelock,
701
        fee_ppm = EXCLUDED.fee_ppm,
702
        base_fee_msat = EXCLUDED.base_fee_msat,
703
        min_htlc_msat = EXCLUDED.min_htlc_msat,
704
        last_update = EXCLUDED.last_update,
705
        disabled = EXCLUDED.disabled,
706
        max_htlc_msat = EXCLUDED.max_htlc_msat,
707
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
708
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
709
        signature = EXCLUDED.signature
710
WHERE EXCLUDED.last_update > channel_policies.last_update
711
RETURNING id
712
`
713

714
type UpsertEdgePolicyParams struct {
715
        Version                 int16
716
        ChannelID               int64
717
        NodeID                  int64
718
        Timelock                int32
719
        FeePpm                  int64
720
        BaseFeeMsat             int64
721
        MinHtlcMsat             int64
722
        LastUpdate              sql.NullInt64
723
        Disabled                sql.NullBool
724
        MaxHtlcMsat             sql.NullInt64
725
        InboundBaseFeeMsat      sql.NullInt64
726
        InboundFeeRateMilliMsat sql.NullInt64
727
        Signature               []byte
728
}
729

NEW
730
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
NEW
731
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
NEW
732
                arg.Version,
×
NEW
733
                arg.ChannelID,
×
NEW
734
                arg.NodeID,
×
NEW
735
                arg.Timelock,
×
NEW
736
                arg.FeePpm,
×
NEW
737
                arg.BaseFeeMsat,
×
NEW
738
                arg.MinHtlcMsat,
×
NEW
739
                arg.LastUpdate,
×
NEW
740
                arg.Disabled,
×
NEW
741
                arg.MaxHtlcMsat,
×
NEW
742
                arg.InboundBaseFeeMsat,
×
NEW
743
                arg.InboundFeeRateMilliMsat,
×
NEW
744
                arg.Signature,
×
NEW
745
        )
×
NEW
746
        var id int64
×
NEW
747
        err := row.Scan(&id)
×
NEW
748
        return id, err
×
NEW
749
}
×
750

751
const upsertNode = `-- name: UpsertNode :one
752
/* ─────────────────────────────────────────────
753
   nodes table queries
754
   ─────────────────────────────────────────────
755
*/
756

757
INSERT INTO nodes (
758
    version, pub_key, alias, last_update, color, signature
759
) VALUES (
760
    $1, $2, $3, $4, $5, $6
761
)
762
ON CONFLICT (pub_key, version)
763
    -- Update the following fields if a conflict occurs on pub_key
764
    -- and version.
765
    DO UPDATE SET
766
        alias = EXCLUDED.alias,
767
        last_update = EXCLUDED.last_update,
768
        color = EXCLUDED.color,
769
        signature = EXCLUDED.signature
770
WHERE nodes.last_update IS NULL
771
    OR EXCLUDED.last_update > nodes.last_update
772
RETURNING id
773
`
774

775
type UpsertNodeParams struct {
776
        Version    int16
777
        PubKey     []byte
778
        Alias      sql.NullString
779
        LastUpdate sql.NullInt64
780
        Color      sql.NullString
781
        Signature  []byte
782
}
783

784
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
785
        row := q.db.QueryRowContext(ctx, upsertNode,
×
786
                arg.Version,
×
787
                arg.PubKey,
×
788
                arg.Alias,
×
789
                arg.LastUpdate,
×
790
                arg.Color,
×
791
                arg.Signature,
×
792
        )
×
793
        var id int64
×
794
        err := row.Scan(&id)
×
795
        return id, err
×
796
}
×
797

798
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
799
/* ─────────────────────────────────────────────
800
   node_extra_types table queries
801
   ─────────────────────────────────────────────
802
*/
803

804
INSERT INTO node_extra_types (
805
    node_id, type, value
806
)
807
VALUES ($1, $2, $3)
808
ON CONFLICT (type, node_id)
809
    -- Update the value if a conflict occurs on type
810
    -- and node_id.
811
    DO UPDATE SET value = EXCLUDED.value
812
`
813

814
type UpsertNodeExtraTypeParams struct {
815
        NodeID int64
816
        Type   int64
817
        Value  []byte
818
}
819

820
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
821
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
822
        return err
×
823
}
×
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

© 2025 Coveralls, Inc