-
Notifications
You must be signed in to change notification settings - Fork 26
/
scripts.go
36 lines (35 loc) · 1.02 KB
/
scripts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
func RunAggregateOldTransactions() {
// twoMonthsAgo := time.Now().AddDate(0, -2, 0)
// yearBegin := time.Date(twoMonthsAgo.Year(), 1, 0, 0, 0, 0, 0, time.FixedZone("UTC", 0))
//
// var users []int
// if err := pg.Select(&users, "SELECT id FROM accounts"); err != nil {
// log.Fatal().Err(err).Msg("failed to get users")
// }
//
// txn, err := pg.BeginTxx(ctx, &sql.TxOptions{ Isolation: sql.LevelSerializable })()
// if err != nil {
// log.Fatal().Err(err).Msg("failed to start transaction")
// }
//
// for _, user := range users {
// log.Printf("user %d", user)
//
// var agg struct {
// Balance int64 `db:"amount"`
// Fees int64 `db:"fees"`
// }
// if err := txn.Get(&agg, `
// SELECT
// coalesce(sum(amount), 0) AS amount,
// coalesce(sum(fees), 0) AS fees
// FROM lightning.account_txn
// WHERE account_id = $1
// AND pending = false
// `, user); err != nil {
// log.Fatal().Err(err).Msg("failed to query user")
// }
//
// }
}