Skip to content

Commit a9626b3

Browse files
committed
refactor: split code into more files
1 parent ad7d081 commit a9626b3

File tree

6 files changed

+82
-62
lines changed

6 files changed

+82
-62
lines changed

sql/config.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ import (
77
)
88

99
type (
10-
// Config interface
11-
Config interface {
12-
DriverName() string
13-
DataSourceName() string
14-
MaxOpenConnections() int
15-
MaxIdleConnections() int
16-
ConnectionMaxLifetime() time.Duration
17-
ConnectionMaxIdleTime() time.Duration
18-
}
19-
2010
// ConnConfig struct
2111
ConnConfig struct {
2212
driverName string

sql/interfaces.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package sql
2+
3+
import (
4+
"database/sql"
5+
"time"
6+
)
7+
8+
type (
9+
// Config interface
10+
Config interface {
11+
DriverName() string
12+
DataSourceName() string
13+
MaxOpenConnections() int
14+
MaxIdleConnections() int
15+
ConnectionMaxLifetime() time.Duration
16+
ConnectionMaxIdleTime() time.Duration
17+
}
18+
19+
// Service is the interface for the service
20+
Service interface {
21+
DB() *sql.DB
22+
Migrate(queries ...string) error
23+
CreateTransaction(fn TransactionFn) error
24+
Exec(query *string, params ...interface{}) (sql.Result, error)
25+
QueryRow(query *string, params ...interface{}) *sql.Row
26+
ScanRow(row *sql.Row, destinations ...interface{}) error
27+
}
28+
)

sql/pgxpool/interfaces.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package pgxpool
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/jackc/pgx/v5"
8+
"github.com/jackc/pgx/v5/pgconn"
9+
"github.com/jackc/pgx/v5/pgxpool"
10+
)
11+
12+
type (
13+
// PoolHandler interface
14+
PoolHandler interface {
15+
Connect() (*pgxpool.Pool, error)
16+
Pool() (*pgxpool.Pool, error)
17+
Disconnect()
18+
}
19+
20+
// Service is the interface for the service
21+
Service interface {
22+
Pool() *pgxpool.Pool
23+
Migrate(queries ...string) error
24+
CreateTransaction(fn TransactionWithCtxFn) error
25+
CreateTransactionWithCtx(
26+
ctx context.Context,
27+
fn TransactionWithCtxFn,
28+
) error
29+
Exec(query *string, params ...interface{}) (*pgconn.CommandTag, error)
30+
ExecWithCtx(
31+
ctx context.Context,
32+
query *string,
33+
params ...interface{},
34+
) (*pgconn.CommandTag, error)
35+
Query(query *string, params ...interface{}) (pgx.Rows, error)
36+
QueryWithCtx(
37+
ctx context.Context,
38+
query *string,
39+
params ...interface{},
40+
) (pgx.Rows, error)
41+
QueryRow(query *string, params ...interface{}) (pgx.Row, error)
42+
QueryRowWithCtx(
43+
ctx context.Context,
44+
query *string,
45+
params ...interface{},
46+
) (pgx.Row, error)
47+
ScanRow(row pgx.Row, destinations ...interface{}) error
48+
SetStatTicker(
49+
duration time.Duration,
50+
fn func(*pgxpool.Stat),
51+
)
52+
ClearStatTicker()
53+
}
54+
)

sql/pgxpool/pool.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
)
99

1010
type (
11-
// PoolHandler interface
12-
PoolHandler interface {
13-
Connect() (*pgxpool.Pool, error)
14-
Pool() (*pgxpool.Pool, error)
15-
Disconnect()
16-
}
17-
1811
// DefaultPoolHandler struct
1912
DefaultPoolHandler struct {
2013
config Config

sql/pgxpool/service.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,6 @@ import (
1111
)
1212

1313
type (
14-
// Service is the interface for the service
15-
Service interface {
16-
Pool() *pgxpool.Pool
17-
Migrate(queries ...string) error
18-
CreateTransaction(fn TransactionWithCtxFn) error
19-
CreateTransactionWithCtx(
20-
ctx context.Context,
21-
fn TransactionWithCtxFn,
22-
) error
23-
Exec(query *string, params ...interface{}) (*pgconn.CommandTag, error)
24-
ExecWithCtx(
25-
ctx context.Context,
26-
query *string,
27-
params ...interface{},
28-
) (*pgconn.CommandTag, error)
29-
Query(query *string, params ...interface{}) (pgx.Rows, error)
30-
QueryWithCtx(
31-
ctx context.Context,
32-
query *string,
33-
params ...interface{},
34-
) (pgx.Rows, error)
35-
QueryRow(query *string, params ...interface{}) (pgx.Row, error)
36-
QueryRowWithCtx(
37-
ctx context.Context,
38-
query *string,
39-
params ...interface{},
40-
) (pgx.Row, error)
41-
ScanRow(row pgx.Row, destinations ...interface{}) error
42-
SetStatTicker(
43-
duration time.Duration,
44-
fn func(*pgxpool.Stat),
45-
)
46-
ClearStatTicker()
47-
}
48-
4914
// DefaultService is the default service struct
5015
DefaultService struct {
5116
pool *pgxpool.Pool

sql/service.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ import (
77
)
88

99
type (
10-
// Service is the interface for the service
11-
Service interface {
12-
DB() *sql.DB
13-
Migrate(queries ...string) error
14-
CreateTransaction(fn TransactionFn) error
15-
Exec(query *string, params ...interface{}) (sql.Result, error)
16-
QueryRow(query *string, params ...interface{}) *sql.Row
17-
ScanRow(row *sql.Row, destinations ...interface{}) error
18-
}
19-
2010
// DefaultService is the default service struct
2111
DefaultService struct {
2212
db *sql.DB

0 commit comments

Comments
 (0)