conn.go 634 Bytes
Newer Older
Vladimir Barsukov's avatar
Vladimir Barsukov committed
1
2
3
4
5
6
7
8
9
10
package zdb

import (
	"fmt"
	"github.com/jackc/pgx/v5/pgxpool"
)

type Conn struct {
	*pgxpool.Pool

Vladimir Barsukov's avatar
zgo    
Vladimir Barsukov committed
11
12
13
14
	Index   int
	Mode    connMode
	Alive   bool
	PingTry int
Vladimir Barsukov's avatar
Vladimir Barsukov committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
}

type connMode int

const (
	ConnModeMaster connMode = iota
	ConnModeSync
	ConnModeAsync
	connModePool
)

func (c connMode) String() string {
	switch c {
	case ConnModeMaster:
		return "master"
	case ConnModeSync:
		return "sync"
	case ConnModeAsync:
		return "async"
	case connModePool:
		return "pool"
	default:
		return "unknown"
	}
}

func (c Conn) ToString() string {
	return fmt.Sprintf("%s: %s:%d", c.Mode, c.Config().ConnConfig.Host, c.Config().ConnConfig.Port)
}