Skip to content

Commit 0347e2d

Browse files
committed
sqlcmig6: add sqlcmig6 package
This commit introduces the `sqlcmig6` package, which at the time of this commit contains the same queries and models as `sqlc` package. Importantly though, once the kvdb to sql migration is made available in production, the `sqlcmig6` package will not change, as it is intended to represent the sql db as it was at the time of the migration. The sqlcmig6 package is therefore intended to be used in the kvdb to sql migration code, as it is will always be compatible with the sql database when all sql migrations prior to the kvdb to sql migration are applied. When additional sql migrations are added in the future, they may effect the `sqlc` package in such a way that the standard `sqlc` queries and models aren't compatible with kvdb to sql migration code any longer. By preserving the `sqlcmig6` package, we ensure that the kvdb to sql migration code can always use the same queries and models that were available at the time of the migration, even if the `sqlc` package changes in the future. Note that the `sqlcmig6` package have not been generated by `sqlc` (the queries and models are copied from the `sqlc` package), as it is not intended to be changed in the future.
1 parent 16cf42e commit 0347e2d

File tree

10 files changed

+2089
-0
lines changed

10 files changed

+2089
-0
lines changed

db/sqlcmig6/accounts.sql.go

Lines changed: 390 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,390 @@
1+
package sqlcmig6
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"time"
7+
)
8+
9+
const addAccountInvoice = `-- name: AddAccountInvoice :exec
10+
INSERT INTO account_invoices (account_id, hash)
11+
VALUES ($1, $2)
12+
`
13+
14+
type AddAccountInvoiceParams struct {
15+
AccountID int64
16+
Hash []byte
17+
}
18+
19+
func (q *Queries) AddAccountInvoice(ctx context.Context, arg AddAccountInvoiceParams) error {
20+
_, err := q.db.ExecContext(ctx, addAccountInvoice, arg.AccountID, arg.Hash)
21+
return err
22+
}
23+
24+
const deleteAccount = `-- name: DeleteAccount :exec
25+
DELETE FROM accounts
26+
WHERE id = $1
27+
`
28+
29+
func (q *Queries) DeleteAccount(ctx context.Context, id int64) error {
30+
_, err := q.db.ExecContext(ctx, deleteAccount, id)
31+
return err
32+
}
33+
34+
const deleteAccountPayment = `-- name: DeleteAccountPayment :exec
35+
DELETE FROM account_payments
36+
WHERE hash = $1
37+
AND account_id = $2
38+
`
39+
40+
type DeleteAccountPaymentParams struct {
41+
Hash []byte
42+
AccountID int64
43+
}
44+
45+
func (q *Queries) DeleteAccountPayment(ctx context.Context, arg DeleteAccountPaymentParams) error {
46+
_, err := q.db.ExecContext(ctx, deleteAccountPayment, arg.Hash, arg.AccountID)
47+
return err
48+
}
49+
50+
const getAccount = `-- name: GetAccount :one
51+
SELECT id, alias, label, type, initial_balance_msat, current_balance_msat, last_updated, expiration
52+
FROM accounts
53+
WHERE id = $1
54+
`
55+
56+
func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
57+
row := q.db.QueryRowContext(ctx, getAccount, id)
58+
var i Account
59+
err := row.Scan(
60+
&i.ID,
61+
&i.Alias,
62+
&i.Label,
63+
&i.Type,
64+
&i.InitialBalanceMsat,
65+
&i.CurrentBalanceMsat,
66+
&i.LastUpdated,
67+
&i.Expiration,
68+
)
69+
return i, err
70+
}
71+
72+
const getAccountByLabel = `-- name: GetAccountByLabel :one
73+
SELECT id, alias, label, type, initial_balance_msat, current_balance_msat, last_updated, expiration
74+
FROM accounts
75+
WHERE label = $1
76+
`
77+
78+
func (q *Queries) GetAccountByLabel(ctx context.Context, label sql.NullString) (Account, error) {
79+
row := q.db.QueryRowContext(ctx, getAccountByLabel, label)
80+
var i Account
81+
err := row.Scan(
82+
&i.ID,
83+
&i.Alias,
84+
&i.Label,
85+
&i.Type,
86+
&i.InitialBalanceMsat,
87+
&i.CurrentBalanceMsat,
88+
&i.LastUpdated,
89+
&i.Expiration,
90+
)
91+
return i, err
92+
}
93+
94+
const getAccountIDByAlias = `-- name: GetAccountIDByAlias :one
95+
SELECT id
96+
FROM accounts
97+
WHERE alias = $1
98+
`
99+
100+
func (q *Queries) GetAccountIDByAlias(ctx context.Context, alias int64) (int64, error) {
101+
row := q.db.QueryRowContext(ctx, getAccountIDByAlias, alias)
102+
var id int64
103+
err := row.Scan(&id)
104+
return id, err
105+
}
106+
107+
const getAccountIndex = `-- name: GetAccountIndex :one
108+
SELECT value
109+
FROM account_indices
110+
WHERE name = $1
111+
`
112+
113+
func (q *Queries) GetAccountIndex(ctx context.Context, name string) (int64, error) {
114+
row := q.db.QueryRowContext(ctx, getAccountIndex, name)
115+
var value int64
116+
err := row.Scan(&value)
117+
return value, err
118+
}
119+
120+
const getAccountInvoice = `-- name: GetAccountInvoice :one
121+
SELECT account_id, hash
122+
FROM account_invoices
123+
WHERE account_id = $1
124+
AND hash = $2
125+
`
126+
127+
type GetAccountInvoiceParams struct {
128+
AccountID int64
129+
Hash []byte
130+
}
131+
132+
func (q *Queries) GetAccountInvoice(ctx context.Context, arg GetAccountInvoiceParams) (AccountInvoice, error) {
133+
row := q.db.QueryRowContext(ctx, getAccountInvoice, arg.AccountID, arg.Hash)
134+
var i AccountInvoice
135+
err := row.Scan(&i.AccountID, &i.Hash)
136+
return i, err
137+
}
138+
139+
const getAccountPayment = `-- name: GetAccountPayment :one
140+
SELECT account_id, hash, status, full_amount_msat FROM account_payments
141+
WHERE hash = $1
142+
AND account_id = $2
143+
`
144+
145+
type GetAccountPaymentParams struct {
146+
Hash []byte
147+
AccountID int64
148+
}
149+
150+
func (q *Queries) GetAccountPayment(ctx context.Context, arg GetAccountPaymentParams) (AccountPayment, error) {
151+
row := q.db.QueryRowContext(ctx, getAccountPayment, arg.Hash, arg.AccountID)
152+
var i AccountPayment
153+
err := row.Scan(
154+
&i.AccountID,
155+
&i.Hash,
156+
&i.Status,
157+
&i.FullAmountMsat,
158+
)
159+
return i, err
160+
}
161+
162+
const insertAccount = `-- name: InsertAccount :one
163+
INSERT INTO accounts (type, initial_balance_msat, current_balance_msat, last_updated, label, alias, expiration)
164+
VALUES ($1, $2, $3, $4, $5, $6, $7)
165+
RETURNING id
166+
`
167+
168+
type InsertAccountParams struct {
169+
Type int16
170+
InitialBalanceMsat int64
171+
CurrentBalanceMsat int64
172+
LastUpdated time.Time
173+
Label sql.NullString
174+
Alias int64
175+
Expiration time.Time
176+
}
177+
178+
func (q *Queries) InsertAccount(ctx context.Context, arg InsertAccountParams) (int64, error) {
179+
row := q.db.QueryRowContext(ctx, insertAccount,
180+
arg.Type,
181+
arg.InitialBalanceMsat,
182+
arg.CurrentBalanceMsat,
183+
arg.LastUpdated,
184+
arg.Label,
185+
arg.Alias,
186+
arg.Expiration,
187+
)
188+
var id int64
189+
err := row.Scan(&id)
190+
return id, err
191+
}
192+
193+
const listAccountInvoices = `-- name: ListAccountInvoices :many
194+
SELECT account_id, hash
195+
FROM account_invoices
196+
WHERE account_id = $1
197+
`
198+
199+
func (q *Queries) ListAccountInvoices(ctx context.Context, accountID int64) ([]AccountInvoice, error) {
200+
rows, err := q.db.QueryContext(ctx, listAccountInvoices, accountID)
201+
if err != nil {
202+
return nil, err
203+
}
204+
defer rows.Close()
205+
var items []AccountInvoice
206+
for rows.Next() {
207+
var i AccountInvoice
208+
if err := rows.Scan(&i.AccountID, &i.Hash); err != nil {
209+
return nil, err
210+
}
211+
items = append(items, i)
212+
}
213+
if err := rows.Close(); err != nil {
214+
return nil, err
215+
}
216+
if err := rows.Err(); err != nil {
217+
return nil, err
218+
}
219+
return items, nil
220+
}
221+
222+
const listAccountPayments = `-- name: ListAccountPayments :many
223+
SELECT account_id, hash, status, full_amount_msat
224+
FROM account_payments
225+
WHERE account_id = $1
226+
`
227+
228+
func (q *Queries) ListAccountPayments(ctx context.Context, accountID int64) ([]AccountPayment, error) {
229+
rows, err := q.db.QueryContext(ctx, listAccountPayments, accountID)
230+
if err != nil {
231+
return nil, err
232+
}
233+
defer rows.Close()
234+
var items []AccountPayment
235+
for rows.Next() {
236+
var i AccountPayment
237+
if err := rows.Scan(
238+
&i.AccountID,
239+
&i.Hash,
240+
&i.Status,
241+
&i.FullAmountMsat,
242+
); err != nil {
243+
return nil, err
244+
}
245+
items = append(items, i)
246+
}
247+
if err := rows.Close(); err != nil {
248+
return nil, err
249+
}
250+
if err := rows.Err(); err != nil {
251+
return nil, err
252+
}
253+
return items, nil
254+
}
255+
256+
const listAllAccounts = `-- name: ListAllAccounts :many
257+
SELECT id, alias, label, type, initial_balance_msat, current_balance_msat, last_updated, expiration
258+
FROM accounts
259+
ORDER BY id
260+
`
261+
262+
func (q *Queries) ListAllAccounts(ctx context.Context) ([]Account, error) {
263+
rows, err := q.db.QueryContext(ctx, listAllAccounts)
264+
if err != nil {
265+
return nil, err
266+
}
267+
defer rows.Close()
268+
var items []Account
269+
for rows.Next() {
270+
var i Account
271+
if err := rows.Scan(
272+
&i.ID,
273+
&i.Alias,
274+
&i.Label,
275+
&i.Type,
276+
&i.InitialBalanceMsat,
277+
&i.CurrentBalanceMsat,
278+
&i.LastUpdated,
279+
&i.Expiration,
280+
); err != nil {
281+
return nil, err
282+
}
283+
items = append(items, i)
284+
}
285+
if err := rows.Close(); err != nil {
286+
return nil, err
287+
}
288+
if err := rows.Err(); err != nil {
289+
return nil, err
290+
}
291+
return items, nil
292+
}
293+
294+
const setAccountIndex = `-- name: SetAccountIndex :exec
295+
INSERT INTO account_indices (name, value)
296+
VALUES ($1, $2)
297+
ON CONFLICT (name)
298+
DO UPDATE SET value = $2
299+
`
300+
301+
type SetAccountIndexParams struct {
302+
Name string
303+
Value int64
304+
}
305+
306+
func (q *Queries) SetAccountIndex(ctx context.Context, arg SetAccountIndexParams) error {
307+
_, err := q.db.ExecContext(ctx, setAccountIndex, arg.Name, arg.Value)
308+
return err
309+
}
310+
311+
const updateAccountBalance = `-- name: UpdateAccountBalance :one
312+
UPDATE accounts
313+
SET current_balance_msat = $1
314+
WHERE id = $2
315+
RETURNING id
316+
`
317+
318+
type UpdateAccountBalanceParams struct {
319+
CurrentBalanceMsat int64
320+
ID int64
321+
}
322+
323+
func (q *Queries) UpdateAccountBalance(ctx context.Context, arg UpdateAccountBalanceParams) (int64, error) {
324+
row := q.db.QueryRowContext(ctx, updateAccountBalance, arg.CurrentBalanceMsat, arg.ID)
325+
var id int64
326+
err := row.Scan(&id)
327+
return id, err
328+
}
329+
330+
const updateAccountExpiry = `-- name: UpdateAccountExpiry :one
331+
UPDATE accounts
332+
SET expiration = $1
333+
WHERE id = $2
334+
RETURNING id
335+
`
336+
337+
type UpdateAccountExpiryParams struct {
338+
Expiration time.Time
339+
ID int64
340+
}
341+
342+
func (q *Queries) UpdateAccountExpiry(ctx context.Context, arg UpdateAccountExpiryParams) (int64, error) {
343+
row := q.db.QueryRowContext(ctx, updateAccountExpiry, arg.Expiration, arg.ID)
344+
var id int64
345+
err := row.Scan(&id)
346+
return id, err
347+
}
348+
349+
const updateAccountLastUpdate = `-- name: UpdateAccountLastUpdate :one
350+
UPDATE accounts
351+
SET last_updated = $1
352+
WHERE id = $2
353+
RETURNING id
354+
`
355+
356+
type UpdateAccountLastUpdateParams struct {
357+
LastUpdated time.Time
358+
ID int64
359+
}
360+
361+
func (q *Queries) UpdateAccountLastUpdate(ctx context.Context, arg UpdateAccountLastUpdateParams) (int64, error) {
362+
row := q.db.QueryRowContext(ctx, updateAccountLastUpdate, arg.LastUpdated, arg.ID)
363+
var id int64
364+
err := row.Scan(&id)
365+
return id, err
366+
}
367+
368+
const upsertAccountPayment = `-- name: UpsertAccountPayment :exec
369+
INSERT INTO account_payments (account_id, hash, status, full_amount_msat)
370+
VALUES ($1, $2, $3, $4)
371+
ON CONFLICT (account_id, hash)
372+
DO UPDATE SET status = $3, full_amount_msat = $4
373+
`
374+
375+
type UpsertAccountPaymentParams struct {
376+
AccountID int64
377+
Hash []byte
378+
Status int16
379+
FullAmountMsat int64
380+
}
381+
382+
func (q *Queries) UpsertAccountPayment(ctx context.Context, arg UpsertAccountPaymentParams) error {
383+
_, err := q.db.ExecContext(ctx, upsertAccountPayment,
384+
arg.AccountID,
385+
arg.Hash,
386+
arg.Status,
387+
arg.FullAmountMsat,
388+
)
389+
return err
390+
}

0 commit comments

Comments
 (0)