Passed
Pull Request — master (#2609)
by Tolga
03:04
created

postgres.HealthCheckPeriod   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
package postgres
2
3
import (
4
	"time"
5
)
6
7
// Option - Option type
8
type Option func(*Postgres)
9
10
// MaxConns - Defines maximum number of connections in the pool (maps to pgxpool MaxConns)
11
// Deprecated: Use MaxConns instead of MaxOpenConnections for consistency with pgxpool.
12
// MaxOpenConnections is kept for backward compatibility and internally uses MaxConns.
13
func MaxOpenConnections(size int) Option {
14
	return MaxConns(size)
15
}
16
17
// MaxConns - Defines maximum number of connections in the pool (maps to pgxpool MaxConns)
18
func MaxConns(size int) Option {
19
	return func(c *Postgres) {
20
		c.maxConns = size
21
	}
22
}
23
24
// MaxIdleConnections - Defines maximum idle connections for postgresql db
25
// Deprecated: Use MinConns and/or MinIdleConns instead. This is kept for backward compatibility.
26
// If MinConns is not set, MaxIdleConnections will be used as MinConns (old behavior).
27
// If MinIdleConns is not set, MaxIdleConnections will also be used as MinIdleConns.
28
func MaxIdleConnections(c int) Option {
29
	return func(p *Postgres) {
30
		p.maxIdleConnections = c
31
	}
32
}
33
34
// MinConns - Defines minimum number of connections in the pool
35
// If not set (0) and MaxIdleConnections is set, MaxIdleConnections will be used for backward compatibility (old behavior).
36
func MinConns(c int) Option {
37
	return func(p *Postgres) {
38
		p.minConns = c
39
	}
40
}
41
42
// MinIdleConns - Defines minimum number of idle connections in the pool
43
// This is superior to MinConns for ensuring idle connections are always available.
44
// If not set and MaxIdleConnections is set, MaxIdleConnections will be used for backward compatibility.
45
// Note: MaxIdleConnections also affects MinConns if MinConns is not set.
46
func MinIdleConns(c int) Option {
47
	return func(p *Postgres) {
48
		p.minIdleConns = c
49
	}
50
}
51
52
// MaxConnectionIdleTime - Defines maximum connection idle for postgresql db
53
func MaxConnectionIdleTime(d time.Duration) Option {
54
	return func(p *Postgres) {
55
		p.maxConnectionIdleTime = d
56
	}
57
}
58
59
// MaxConnectionLifeTime - Defines maximum connection lifetime for postgresql db
60
func MaxConnectionLifeTime(d time.Duration) Option {
61
	return func(p *Postgres) {
62
		p.maxConnectionLifeTime = d
63
	}
64
}
65
66
// HealthCheckPeriod - Defines the period between health checks on idle connections
67
func HealthCheckPeriod(d time.Duration) Option {
68
	return func(p *Postgres) {
69
		p.healthCheckPeriod = d
70
	}
71
}
72
73
// MaxConnLifetimeJitter - Defines the jitter added to MaxConnLifetime to prevent all connections from expiring at once
74
func MaxConnLifetimeJitter(d time.Duration) Option {
75
	return func(p *Postgres) {
76
		p.maxConnLifetimeJitter = d
77
	}
78
}
79
80
// ConnectTimeout - Defines the maximum time to wait when establishing a new connection
81
func ConnectTimeout(d time.Duration) Option {
82
	return func(p *Postgres) {
83
		p.connectTimeout = d
84
	}
85
}
86
87
func MaxDataPerWrite(v int) Option {
88
	return func(c *Postgres) {
89
		c.maxDataPerWrite = v
90
	}
91
}
92
93
func WatchBufferSize(v int) Option {
94
	return func(c *Postgres) {
95
		c.watchBufferSize = v
96
	}
97
}
98
99
func MaxRetries(v int) Option {
100
	return func(c *Postgres) {
101
		c.maxRetries = v
102
	}
103
}
104