Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Add missing context for postgresql module #29

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/store/postgresql.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"context"
"fmt"
"strings"
"time"
Expand All @@ -22,8 +23,7 @@ func NewPostgresqlClient(connStr string) *sql.DB {
if err != nil {
panic(err)
}

_, err = db.Query(`
rows, err := db.Query(`
CREATE TABLE IF NOT EXISTS users (
id varchar(255) NOT NULL,
username varchar(255) NOT NULL,
Expand All @@ -33,6 +33,7 @@ func NewPostgresqlClient(connStr string) *sql.DB {
PRIMARY KEY(id)
)
`)
defer rows.Close()
if err != nil {
panic(err)
}
Expand All @@ -48,9 +49,14 @@ func NewPostgresqlStore(db *sql.DB) PostgresqlStore {
}

// Ping will check if the connection works right
func (s PostgresqlStore) Ping() error {
_, err := s.db.Query("SELECT 1")
return err
func (s PostgresqlStore) Ping(ctx context.Context) error {
conn, err := s.db.Conn(ctx)
if err != nil {
return err
}
defer conn.Close()

return conn.PingContext(ctx)
}

// WriteUser will write a user object to postgres
Expand Down