Refactor of pgsql client
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package postgresql
|
package postgresql
|
||||||
|
|
||||||
|
// Wrapper around jackx/pgx pool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -9,7 +11,18 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Connect(connStr string) (*pgxpool.Pool, error) {
|
type Database struct {
|
||||||
|
*pgxpool.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDB(connStr string) *Database {
|
||||||
|
db := &Database{}
|
||||||
|
db.Connect(connStr)
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Database) Connect(connStr string) (*pgxpool.Pool, error) {
|
||||||
pool, err := pgxpool.New(context.Background(), connStr)
|
pool, err := pgxpool.New(context.Background(), connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user