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

lightningnetwork / lnd / 15408150936

03 Jun 2025 03:56AM UTC coverage: 68.378%. First build
15408150936

Pull #9887

github

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

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

134072 of 196074 relevant lines covered (68.38%)

21822.15 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 getChannelBySCID = `-- name: GetChannelBySCID :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 GetChannelBySCIDParams struct {
190
        Scid    []byte
191
        Version int16
192
}
193

194
type GetChannelBySCIDRow 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) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GetChannelBySCIDRow, error) {
×
213
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
NEW
214
        var i GetChannelBySCIDRow
×
215
        err := row.Scan(
×
216
                &i.ID,
×
217
                &i.Version,
×
218
                &i.Scid,
×
219
                &i.NodeID1,
×
220
                &i.NodeID2,
×
221
                &i.Outpoint,
×
222
                &i.Capacity,
×
223
                &i.BitcoinKey1,
×
224
                &i.BitcoinKey2,
×
225
                &i.Node1Signature,
×
226
                &i.Node2Signature,
×
227
                &i.Bitcoin1Signature,
×
228
                &i.Bitcoin2Signature,
×
NEW
229
                &i.Node1PubKey,
×
NEW
230
                &i.Node2PubKey,
×
231
        )
×
232
        return i, err
×
233
}
×
234

235
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
236
SELECT channel_policy_id, type, value
237
FROM channel_policy_extra_types
238
WHERE channel_policy_id = $1
239
`
240

NEW
241
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) ([]ChannelPolicyExtraType, error) {
×
NEW
242
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, channelPolicyID)
×
NEW
243
        if err != nil {
×
NEW
244
                return nil, err
×
NEW
245
        }
×
NEW
246
        defer rows.Close()
×
NEW
247
        var items []ChannelPolicyExtraType
×
NEW
248
        for rows.Next() {
×
NEW
249
                var i ChannelPolicyExtraType
×
NEW
250
                if err := rows.Scan(&i.ChannelPolicyID, &i.Type, &i.Value); err != nil {
×
NEW
251
                        return nil, err
×
NEW
252
                }
×
NEW
253
                items = append(items, i)
×
254
        }
NEW
255
        if err := rows.Close(); err != nil {
×
NEW
256
                return nil, err
×
NEW
257
        }
×
NEW
258
        if err := rows.Err(); err != nil {
×
NEW
259
                return nil, err
×
NEW
260
        }
×
NEW
261
        return items, nil
×
262
}
263

264
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
265
SELECT node_id, type, value
266
FROM node_extra_types
267
WHERE node_id = $1
268
`
269

270
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
271
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
272
        if err != nil {
×
273
                return nil, err
×
274
        }
×
275
        defer rows.Close()
×
276
        var items []NodeExtraType
×
277
        for rows.Next() {
×
278
                var i NodeExtraType
×
279
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
280
                        return nil, err
×
281
                }
×
282
                items = append(items, i)
×
283
        }
284
        if err := rows.Close(); err != nil {
×
285
                return nil, err
×
286
        }
×
287
        if err := rows.Err(); err != nil {
×
288
                return nil, err
×
289
        }
×
290
        return items, nil
×
291
}
292

293
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
294
SELECT a.type, a.address
295
FROM nodes n
296
LEFT JOIN node_addresses a ON a.node_id = n.id
297
WHERE n.pub_key = $1 AND n.version = $2
298
ORDER BY a.type ASC, a.position ASC
299
`
300

301
type GetNodeAddressesByPubKeyParams struct {
302
        PubKey  []byte
303
        Version int16
304
}
305

306
type GetNodeAddressesByPubKeyRow struct {
307
        Type    sql.NullInt16
308
        Address sql.NullString
309
}
310

311
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
312
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
313
        if err != nil {
×
314
                return nil, err
×
315
        }
×
316
        defer rows.Close()
×
317
        var items []GetNodeAddressesByPubKeyRow
×
318
        for rows.Next() {
×
319
                var i GetNodeAddressesByPubKeyRow
×
320
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
321
                        return nil, err
×
322
                }
×
323
                items = append(items, i)
×
324
        }
325
        if err := rows.Close(); err != nil {
×
326
                return nil, err
×
327
        }
×
328
        if err := rows.Err(); err != nil {
×
329
                return nil, err
×
330
        }
×
331
        return items, nil
×
332
}
333

334
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
335
SELECT id, version, pub_key, alias, last_update, color, signature
336
FROM nodes
337
WHERE pub_key = $1
338
  AND version = $2
339
`
340

341
type GetNodeByPubKeyParams struct {
342
        PubKey  []byte
343
        Version int16
344
}
345

346
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
347
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
348
        var i Node
×
349
        err := row.Scan(
×
350
                &i.ID,
×
351
                &i.Version,
×
352
                &i.PubKey,
×
353
                &i.Alias,
×
354
                &i.LastUpdate,
×
355
                &i.Color,
×
356
                &i.Signature,
×
357
        )
×
358
        return i, err
×
359
}
×
360

361
const getNodeFeatures = `-- name: GetNodeFeatures :many
362
SELECT node_id, feature_bit
363
FROM node_features
364
WHERE node_id = $1
365
`
366

367
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
368
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
369
        if err != nil {
×
370
                return nil, err
×
371
        }
×
372
        defer rows.Close()
×
373
        var items []NodeFeature
×
374
        for rows.Next() {
×
375
                var i NodeFeature
×
376
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
377
                        return nil, err
×
378
                }
×
379
                items = append(items, i)
×
380
        }
381
        if err := rows.Close(); err != nil {
×
382
                return nil, err
×
383
        }
×
384
        if err := rows.Err(); err != nil {
×
385
                return nil, err
×
386
        }
×
387
        return items, nil
×
388
}
389

390
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
391
SELECT f.feature_bit
392
FROM nodes n
393
    JOIN node_features f ON f.node_id = n.id
394
WHERE n.pub_key = $1
395
  AND n.version = $2
396
`
397

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

403
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
404
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
405
        if err != nil {
×
406
                return nil, err
×
407
        }
×
408
        defer rows.Close()
×
409
        var items []int32
×
410
        for rows.Next() {
×
411
                var feature_bit int32
×
412
                if err := rows.Scan(&feature_bit); err != nil {
×
413
                        return nil, err
×
414
                }
×
415
                items = append(items, feature_bit)
×
416
        }
417
        if err := rows.Close(); err != nil {
×
418
                return nil, err
×
419
        }
×
420
        if err := rows.Err(); err != nil {
×
421
                return nil, err
×
422
        }
×
423
        return items, nil
×
424
}
425

426
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
427
SELECT id, version, pub_key, alias, last_update, color, signature
428
FROM nodes
429
WHERE last_update >= $1
430
  AND last_update < $2
431
`
432

433
type GetNodesByLastUpdateRangeParams struct {
434
        StartTime sql.NullInt64
435
        EndTime   sql.NullInt64
436
}
437

438
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
439
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
440
        if err != nil {
×
441
                return nil, err
×
442
        }
×
443
        defer rows.Close()
×
444
        var items []Node
×
445
        for rows.Next() {
×
446
                var i Node
×
447
                if err := rows.Scan(
×
448
                        &i.ID,
×
449
                        &i.Version,
×
450
                        &i.PubKey,
×
451
                        &i.Alias,
×
452
                        &i.LastUpdate,
×
453
                        &i.Color,
×
454
                        &i.Signature,
×
455
                ); err != nil {
×
456
                        return nil, err
×
457
                }
×
458
                items = append(items, i)
×
459
        }
460
        if err := rows.Close(); err != nil {
×
461
                return nil, err
×
462
        }
×
463
        if err := rows.Err(); err != nil {
×
464
                return nil, err
×
465
        }
×
466
        return items, nil
×
467
}
468

469
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
470
SELECT sn.node_id, n.pub_key
471
FROM source_nodes sn
472
    JOIN nodes n ON sn.node_id = n.id
473
WHERE n.version = $1
474
`
475

476
type GetSourceNodesByVersionRow struct {
477
        NodeID int64
478
        PubKey []byte
479
}
480

481
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
482
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
483
        if err != nil {
×
484
                return nil, err
×
485
        }
×
486
        defer rows.Close()
×
487
        var items []GetSourceNodesByVersionRow
×
488
        for rows.Next() {
×
489
                var i GetSourceNodesByVersionRow
×
490
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
491
                        return nil, err
×
492
                }
×
493
                items = append(items, i)
×
494
        }
495
        if err := rows.Close(); err != nil {
×
496
                return nil, err
×
497
        }
×
498
        if err := rows.Err(); err != nil {
×
499
                return nil, err
×
500
        }
×
501
        return items, nil
×
502
}
503

504
const highestSCID = `-- name: HighestSCID :one
505
SELECT scid
506
FROM channels
507
WHERE version = $1
508
ORDER BY scid DESC
509
LIMIT 1
510
`
511

512
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
513
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
514
        var scid []byte
×
515
        err := row.Scan(&scid)
×
516
        return scid, err
×
517
}
×
518

519
const insertChannelFeature = `-- name: InsertChannelFeature :exec
520
/* ─────────────────────────────────────────────
521
   channel_features table queries
522
   ─────────────────────────────────────────────
523
*/
524

525
INSERT INTO channel_features (
526
    channel_id, feature_bit
527
) VALUES (
528
    $1, $2
529
)
530
`
531

532
type InsertChannelFeatureParams struct {
533
        ChannelID  int64
534
        FeatureBit int32
535
}
536

537
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
538
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
539
        return err
×
540
}
×
541

542
const insertNodeAddress = `-- name: InsertNodeAddress :exec
543
/* ─────────────────────────────────────────────
544
   node_addresses table queries
545
   ─────────────────────────────────────────────
546
*/
547

548
INSERT INTO node_addresses (
549
    node_id,
550
    type,
551
    address,
552
    position
553
) VALUES (
554
    $1, $2, $3, $4
555
 )
556
`
557

558
type InsertNodeAddressParams struct {
559
        NodeID   int64
560
        Type     int16
561
        Address  string
562
        Position int32
563
}
564

565
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
566
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
567
                arg.NodeID,
×
568
                arg.Type,
×
569
                arg.Address,
×
570
                arg.Position,
×
571
        )
×
572
        return err
×
573
}
×
574

575
const insertNodeFeature = `-- name: InsertNodeFeature :exec
576
/* ─────────────────────────────────────────────
577
   node_features table queries
578
   ─────────────────────────────────────────────
579
*/
580

581
INSERT INTO node_features (
582
    node_id, feature_bit
583
) VALUES (
584
    $1, $2
585
)
586
`
587

588
type InsertNodeFeatureParams struct {
589
        NodeID     int64
590
        FeatureBit int32
591
}
592

593
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
594
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
595
        return err
×
596
}
×
597

598
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
599
/* ─────────────────────────────────────────────
600
   channel_policy_extra_types table queries
601
   ─────────────────────────────────────────────
602
*/
603

604
INSERT INTO channel_policy_extra_types (
605
    channel_policy_id, type, value
606
)
607
VALUES ($1, $2, $3)
608
ON CONFLICT (type, channel_policy_id)
609
    -- Update the value if a conflict occurs on type
610
    -- and node_id.
611
    DO UPDATE SET value = EXCLUDED.value
612
`
613

614
type UpsertChanPolicyExtraTypeParams struct {
615
        ChannelPolicyID int64
616
        Type            int64
617
        Value           []byte
618
}
619

NEW
620
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
NEW
621
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
NEW
622
        return err
×
NEW
623
}
×
624

625
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
626
/* ─────────────────────────────────────────────
627
   channel_policies table queries
628
   ─────────────────────────────────────────────
629
*/
630

631
INSERT INTO channel_policies (
632
    version, channel_id, node_id, timelock, fee_ppm,
633
    base_fee_msat, min_htlc_msat, last_update, disabled,
634
    max_htlc_msat, signature
635
) VALUES  (
636
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
637
)
638
ON CONFLICT (channel_id, node_id, version)
639
    -- Update the following fields if a conflict occurs on channel_id,
640
    -- node_id, and version.
641
    DO UPDATE SET
642
        timelock = EXCLUDED.timelock,
643
        fee_ppm = EXCLUDED.fee_ppm,
644
        base_fee_msat = EXCLUDED.base_fee_msat,
645
        min_htlc_msat = EXCLUDED.min_htlc_msat,
646
        last_update = EXCLUDED.last_update,
647
        disabled = EXCLUDED.disabled,
648
        max_htlc_msat = EXCLUDED.max_htlc_msat,
649
        signature = EXCLUDED.signature
650
WHERE EXCLUDED.last_update > channel_policies.last_update
651
RETURNING id
652
`
653

654
type UpsertEdgePolicyParams struct {
655
        Version     int16
656
        ChannelID   int64
657
        NodeID      int64
658
        Timelock    int32
659
        FeePpm      int64
660
        BaseFeeMsat int64
661
        MinHtlcMsat int64
662
        LastUpdate  sql.NullInt64
663
        Disabled    sql.NullBool
664
        MaxHtlcMsat sql.NullInt64
665
        Signature   []byte
666
}
667

NEW
668
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
NEW
669
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
NEW
670
                arg.Version,
×
NEW
671
                arg.ChannelID,
×
NEW
672
                arg.NodeID,
×
NEW
673
                arg.Timelock,
×
NEW
674
                arg.FeePpm,
×
NEW
675
                arg.BaseFeeMsat,
×
NEW
676
                arg.MinHtlcMsat,
×
NEW
677
                arg.LastUpdate,
×
NEW
678
                arg.Disabled,
×
NEW
679
                arg.MaxHtlcMsat,
×
NEW
680
                arg.Signature,
×
NEW
681
        )
×
NEW
682
        var id int64
×
NEW
683
        err := row.Scan(&id)
×
NEW
684
        return id, err
×
NEW
685
}
×
686

687
const upsertNode = `-- name: UpsertNode :one
688
/* ─────────────────────────────────────────────
689
   nodes table queries
690
   ─────────────────────────────────────────────
691
*/
692

693
INSERT INTO nodes (
694
    version, pub_key, alias, last_update, color, signature
695
) VALUES (
696
    $1, $2, $3, $4, $5, $6
697
)
698
ON CONFLICT (pub_key, version)
699
    -- Update the following fields if a conflict occurs on pub_key
700
    -- and version.
701
    DO UPDATE SET
702
        alias = EXCLUDED.alias,
703
        last_update = EXCLUDED.last_update,
704
        color = EXCLUDED.color,
705
        signature = EXCLUDED.signature
706
WHERE nodes.last_update IS NULL
707
    OR EXCLUDED.last_update > nodes.last_update
708
RETURNING id
709
`
710

711
type UpsertNodeParams struct {
712
        Version    int16
713
        PubKey     []byte
714
        Alias      sql.NullString
715
        LastUpdate sql.NullInt64
716
        Color      sql.NullString
717
        Signature  []byte
718
}
719

720
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
721
        row := q.db.QueryRowContext(ctx, upsertNode,
×
722
                arg.Version,
×
723
                arg.PubKey,
×
724
                arg.Alias,
×
725
                arg.LastUpdate,
×
726
                arg.Color,
×
727
                arg.Signature,
×
728
        )
×
729
        var id int64
×
730
        err := row.Scan(&id)
×
731
        return id, err
×
732
}
×
733

734
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
735
/* ─────────────────────────────────────────────
736
   node_extra_types table queries
737
   ─────────────────────────────────────────────
738
*/
739

740
INSERT INTO node_extra_types (
741
    node_id, type, value
742
)
743
VALUES ($1, $2, $3)
744
ON CONFLICT (type, node_id)
745
    -- Update the value if a conflict occurs on type
746
    -- and node_id.
747
    DO UPDATE SET value = EXCLUDED.value
748
`
749

750
type UpsertNodeExtraTypeParams struct {
751
        NodeID int64
752
        Type   int64
753
        Value  []byte
754
}
755

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