File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed
internal/session/postgresql Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change 1- package postgresql
1+ package postgresql
2+
3+ import (
4+ "database/sql"
5+ "fmt"
6+ )
7+
8+ /*
9+ PostgreSQL database stores logs of all expired sessions and processed transactions results
10+ this is an archival database and is used to serve archived information to users and admin panel
11+ */
12+
13+ /*
14+ TODO: when application shutsdown, all sessions in Redis are marked expired
15+ make sure to push those expired sessions to PostreSQL database for archival
16+ */
17+
18+ /* PostgreSQL client */
19+ type PGClient struct {
20+ db * sql.DB
21+ }
22+
23+ /* create new PostgreSQL client */
24+ func NewPGClient (connStr string ) (* PGClient , error ) {
25+
26+ /* initiate PostgreSQL connection */
27+ db , err := sql .Open ("postgres" , connStr )
28+ if err != nil {
29+ return nil , fmt .Errorf ("failed to open PostgreSQL connection: %w" , err )
30+ }
31+
32+ /* ping PostgreSQL connection */
33+ if err := db .Ping (); err != nil {
34+ return nil , fmt .Errorf ("failed to ping PostgreSQL: %w" , err )
35+ }
36+
37+ /* return the PostgreSQL client */
38+ return & PGClient {db : db }, nil
39+ }
You can’t perform that action at this time.
0 commit comments