-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdashboardusers.go
49 lines (39 loc) · 1.06 KB
/
dashboardusers.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
37
38
39
40
41
42
43
44
45
46
47
48
49
package database
import (
"context"
_ "embed"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4/pgxpool"
"time"
)
type DashboardUsersTable struct {
*pgxpool.Pool
}
func newDashboardUsersTable(db *pgxpool.Pool) *DashboardUsersTable {
return &DashboardUsersTable{
db,
}
}
var (
//go:embed sql/dashboard_users/schema.sql
dashboardUsersSchema string
//go:embed sql/dashboard_users/upsert.sql
dashboardUsersUpsert string
//go:embed sql/dashboard_users/purge_old_users.sql
dashboardPurgeOldUsers string
)
func (d *DashboardUsersTable) Schema() string {
return dashboardUsersSchema
}
func (d *DashboardUsersTable) UpdateLastSeen(ctx context.Context, userId uint64) error {
_, err := d.Exec(ctx, dashboardUsersUpsert, userId, time.Now())
return err
}
func (d *DashboardUsersTable) PurgeOldUsers(ctx context.Context, threshold time.Duration) (int64, error) {
var interval pgtype.Interval
if err := interval.Set(threshold); err != nil {
return 0, err
}
metadata, err := d.Exec(ctx, dashboardPurgeOldUsers, threshold)
return metadata.RowsAffected(), err
}