From c5ca812732a9287f973ee3d1abf3e53305f05abd Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Wed, 15 May 2024 21:45:03 +0530 Subject: [PATCH] Apply minor query exec cleanup. --- stores/postgres/postgres.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/stores/postgres/postgres.go b/stores/postgres/postgres.go index 5d05c03..9bd171a 100644 --- a/stores/postgres/postgres.go +++ b/stores/postgres/postgres.go @@ -47,7 +47,6 @@ func (e *Err) Code() int { type queries struct { create *sql.Stmt get *sql.Stmt - getAll *sql.Stmt update *sql.Stmt delete *sql.Stmt clear *sql.Stmt @@ -175,7 +174,7 @@ func (s *Store) GetAll(id string, keys ...string) (map[string]interface{}, error } var b []byte - err := s.q.getAll.QueryRow(id, s.opt.TTL.Seconds()).Scan(&b) + err := s.q.get.QueryRow(id, s.opt.TTL.Seconds()).Scan(&b) if err != nil { return nil, err } @@ -307,7 +306,7 @@ func (s *Store) Clear(id string) error { return ErrInvalidSession } - res, err := s.db.Exec(fmt.Sprintf("UPDATE %s SET data = '{}'::JSONB WHERE id=$1", s.opt.Table), id) + res, err := s.q.clear.Exec(id) if err != nil { return err } @@ -341,11 +340,6 @@ func (s *Store) prepareQueries() (*queries, error) { return nil, err } - q.getAll, err = s.db.Prepare(fmt.Sprintf("SELECT data FROM %s WHERE id=$1 AND created_at >= NOW() - INTERVAL '1 second' * $2", s.opt.Table)) - if err != nil { - return nil, err - } - q.update, err = s.db.Prepare(fmt.Sprintf("UPDATE %s SET data = data || $2::JSONB WHERE id = $1", s.opt.Table)) if err != nil { return nil, err