mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
use config
This commit is contained in:
@ -2,28 +2,16 @@ package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/alice-lg/alice-lg/pkg/config"
|
||||
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMaxConnsUnconfigured will be returned, if the
|
||||
// the maximum connections are zero.
|
||||
ErrMaxConnsUnconfigured = errors.New("MaxConns not configured")
|
||||
)
|
||||
|
||||
// ConnectOpts database connection options
|
||||
type ConnectOpts struct {
|
||||
URL string
|
||||
MaxConns int32
|
||||
MinConns int32
|
||||
}
|
||||
|
||||
// Connect creates and configures a pgx pool
|
||||
func Connect(ctx context.Context, opts *ConnectOpts) (*pgxpool.Pool, error) {
|
||||
func Connect(ctx context.Context, opts *config.PostgresConfig) (*pgxpool.Pool, error) {
|
||||
// Initialize postgres connection
|
||||
cfg, err := pgxpool.ParseConfig(opts.URL)
|
||||
if err != nil {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/alice-lg/alice-lg/pkg/api"
|
||||
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user