|
| 1 | +package sqlc |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | +) |
| 7 | + |
| 8 | +// makeQueryParams generates a string of query parameters for a SQL query. It is |
| 9 | +// meant to replace the `?` placeholders in a SQL query with numbered parameters |
| 10 | +// like `$1`, `$2`, etc. This is required for the sqlc /*SLICE:<field_name>*/ |
| 11 | +// workaround. See scripts/gen_sqlc_docker.sh for more details. |
| 12 | +func makeQueryParams(numTotalArgs, numListArgs int) string { |
| 13 | + if numListArgs == 0 { |
| 14 | + return "" |
| 15 | + } |
| 16 | + |
| 17 | + var b strings.Builder |
| 18 | + |
| 19 | + // Pre-allocate a rough estimation of the buffer size to avoid |
| 20 | + // re-allocations. A parameter like $1000, takes 6 bytes. |
| 21 | + b.Grow(numListArgs * 6) |
| 22 | + |
| 23 | + diff := numTotalArgs - numListArgs |
| 24 | + for i := 0; i < numListArgs; i++ { |
| 25 | + if i > 0 { |
| 26 | + // We don't need to check the error here because the |
| 27 | + // WriteString method of strings.Builder always returns |
| 28 | + // nil. |
| 29 | + _, _ = b.WriteString(",") |
| 30 | + } |
| 31 | + |
| 32 | + // We don't need to check the error here because the |
| 33 | + // Write method (called by fmt.Fprintf) of strings.Builder |
| 34 | + // always returns nil. |
| 35 | + _, _ = fmt.Fprintf(&b, "$%d", i+diff+1) |
| 36 | + } |
| 37 | + |
| 38 | + return b.String() |
| 39 | +} |
| 40 | + |
| 41 | +// ChannelAndNodes is an interface that provides access to a channel and its |
| 42 | +// two nodes. |
| 43 | +type ChannelAndNodes interface { |
| 44 | + // Channel returns the GraphChannel associated with this interface. |
| 45 | + Channel() GraphChannel |
| 46 | + |
| 47 | + // Node1 returns the first GraphNode associated with this channel. |
| 48 | + Node1() GraphNode |
| 49 | + |
| 50 | + // Node2 returns the second GraphNode associated with this channel. |
| 51 | + Node2() GraphNode |
| 52 | +} |
| 53 | + |
| 54 | +// Channel returns the GraphChannel associated with this interface. |
| 55 | +// |
| 56 | +// NOTE: This method is part of the ChannelAndNodes interface. |
| 57 | +func (r GetChannelsByPolicyLastUpdateRangeRow) Channel() GraphChannel { |
| 58 | + return r.GraphChannel |
| 59 | +} |
| 60 | + |
| 61 | +// Node1 returns the first GraphNode associated with this channel. |
| 62 | +// |
| 63 | +// NOTE: This method is part of the ChannelAndNodes interface. |
| 64 | +func (r GetChannelsByPolicyLastUpdateRangeRow) Node1() GraphNode { |
| 65 | + return r.GraphNode |
| 66 | +} |
| 67 | + |
| 68 | +// Node2 returns the second GraphNode associated with this channel. |
| 69 | +// |
| 70 | +// NOTE: This method is part of the ChannelAndNodes interface. |
| 71 | +func (r GetChannelsByPolicyLastUpdateRangeRow) Node2() GraphNode { |
| 72 | + return r.GraphNode_2 |
| 73 | +} |
| 74 | + |
| 75 | +// ChannelAndNodeIDs is an interface that provides access to a channel and its |
| 76 | +// two node public keys. |
| 77 | +type ChannelAndNodeIDs interface { |
| 78 | + // Channel returns the GraphChannel associated with this interface. |
| 79 | + Channel() GraphChannel |
| 80 | + |
| 81 | + // Node1Pub returns the public key of the first node as a byte slice. |
| 82 | + Node1Pub() []byte |
| 83 | + |
| 84 | + // Node2Pub returns the public key of the second node as a byte slice. |
| 85 | + Node2Pub() []byte |
| 86 | +} |
| 87 | + |
| 88 | +// Channel returns the GraphChannel associated with this interface. |
| 89 | +// |
| 90 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 91 | +func (r GetChannelsBySCIDWithPoliciesRow) Channel() GraphChannel { |
| 92 | + return r.GraphChannel |
| 93 | +} |
| 94 | + |
| 95 | +// Node1Pub returns the public key of the first node as a byte slice. |
| 96 | +// |
| 97 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 98 | +func (r GetChannelsBySCIDWithPoliciesRow) Node1Pub() []byte { |
| 99 | + return r.GraphNode.PubKey |
| 100 | +} |
| 101 | + |
| 102 | +// Node2Pub returns the public key of the second node as a byte slice. |
| 103 | +// |
| 104 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 105 | +func (r GetChannelsBySCIDWithPoliciesRow) Node2Pub() []byte { |
| 106 | + return r.GraphNode_2.PubKey |
| 107 | +} |
| 108 | + |
| 109 | +// Node1 returns the first GraphNode associated with this channel. |
| 110 | +// |
| 111 | +// NOTE: This method is part of the ChannelAndNodes interface. |
| 112 | +func (r GetChannelsBySCIDWithPoliciesRow) Node1() GraphNode { |
| 113 | + return r.GraphNode |
| 114 | +} |
| 115 | + |
| 116 | +// Node2 returns the second GraphNode associated with this channel. |
| 117 | +// |
| 118 | +// NOTE: This method is part of the ChannelAndNodes interface. |
| 119 | +func (r GetChannelsBySCIDWithPoliciesRow) Node2() GraphNode { |
| 120 | + return r.GraphNode_2 |
| 121 | +} |
| 122 | + |
| 123 | +// Channel returns the GraphChannel associated with this interface. |
| 124 | +// |
| 125 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 126 | +func (r GetChannelsByOutpointsRow) Channel() GraphChannel { |
| 127 | + return r.GraphChannel |
| 128 | +} |
| 129 | + |
| 130 | +// Node1Pub returns the public key of the first node as a byte slice. |
| 131 | +// |
| 132 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 133 | +func (r GetChannelsByOutpointsRow) Node1Pub() []byte { |
| 134 | + return r.Node1Pubkey |
| 135 | +} |
| 136 | + |
| 137 | +// Node2Pub returns the public key of the second node as a byte slice. |
| 138 | +// |
| 139 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 140 | +func (r GetChannelsByOutpointsRow) Node2Pub() []byte { |
| 141 | + return r.Node2Pubkey |
| 142 | +} |
| 143 | + |
| 144 | +// Channel returns the GraphChannel associated with this interface. |
| 145 | +// |
| 146 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 147 | +func (r GetChannelsBySCIDRangeRow) Channel() GraphChannel { |
| 148 | + return r.GraphChannel |
| 149 | +} |
| 150 | + |
| 151 | +// Node1Pub returns the public key of the first node as a byte slice. |
| 152 | +// |
| 153 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 154 | +func (r GetChannelsBySCIDRangeRow) Node1Pub() []byte { |
| 155 | + return r.Node1PubKey |
| 156 | +} |
| 157 | + |
| 158 | +// Node2Pub returns the public key of the second node as a byte slice. |
| 159 | +// |
| 160 | +// NOTE: This method is part of the ChannelAndNodeIDs interface. |
| 161 | +func (r GetChannelsBySCIDRangeRow) Node2Pub() []byte { |
| 162 | + return r.Node2PubKey |
| 163 | +} |
0 commit comments