Files
atom/providers/database/postgres/config.go
2023-04-20 12:11:34 +08:00

32 lines
881 B
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package postgres
import (
"fmt"
)
type Config struct {
Username string
Password string
Database string
Host string
Port uint
SslMode string
TimeZone string
Prefix string // 表前缀
Singular bool // 是否开启全局禁用复数true表示开启
MaxIdleConns int // 空闲中的最大连接数
MaxOpenConns int // 打开到数据库的最大连接数
}
func (m *Config) EmptyDsn() string {
dsnTpl := "host=%s user=%s password=%s port=%d dbname=postgres sslmode=disable TimeZone=Asia/Shanghai"
return fmt.Sprintf(dsnTpl, m.Host, m.Username, m.Password, m.Port)
}
// DSN connection dsn
func (m *Config) DSN() string {
dsnTpl := "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s"
return fmt.Sprintf(dsnTpl, m.Host, m.Username, m.Password, m.Database, m.Port, m.SslMode, m.TimeZone)
}