Fixes
This commit is contained in:
@@ -1,36 +1,14 @@
|
|||||||
package postgresql
|
package postgresql
|
||||||
|
|
||||||
// Wrapper around jackx/pgx pool
|
// DB Operations helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return pool, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsDuplicatedRow(err error) error {
|
func IsDuplicatedRow(err error) error {
|
||||||
var pgErr *pgconn.PgError
|
var pgErr *pgconn.PgError
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user