-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_users.go
More file actions
42 lines (35 loc) · 976 Bytes
/
debug_users.go
File metadata and controls
42 lines (35 loc) · 976 Bytes
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
package main
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v5"
)
func main() {
url := os.Getenv("DATABASE_URL")
if url == "" {
fmt.Println("DATABASE_URL required")
os.Exit(1)
}
conn, err := pgx.Connect(context.Background(), url)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
rows, _ := conn.Query(context.Background(), "SELECT id, email, username FROM users")
defer rows.Close()
for rows.Next() {
var id, email, username string
rows.Scan(&id, &email, &username)
fmt.Printf("User: %s (%s) - %s\n", username, email, id)
// List keys for this user
krows, _ := conn.Query(context.Background(), "SELECT id, name, key_prefix FROM api_keys WHERE user_id = $1", id)
defer krows.Close()
for krows.Next() {
var kid, kname, kprefix string
krows.Scan(&kid, &kname, &kprefix)
fmt.Printf(" Key: %s (%s) - %s\n", kname, kprefix, kid)
}
}
}