feat: gen model

This commit is contained in:
Rogee
2024-11-29 17:42:59 +08:00
parent 7bc082abea
commit 725a6de5ab
16 changed files with 348 additions and 60 deletions

View File

@@ -22,6 +22,7 @@ type Config struct {
Username string
Password string
Database string
Schema string
Host string
Port uint
SslMode string
@@ -56,6 +57,10 @@ func (m *Config) checkDefault() {
if m.Port == 0 {
m.Port = 5432
}
if m.Schema == "" {
m.Schema = "public"
}
}
func (m *Config) EmptyDsn() string {
@@ -68,6 +73,7 @@ func (m *Config) EmptyDsn() string {
// DSN connection dsn
func (m *Config) DSN() string {
dsnTpl := "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s"
m.checkDefault()
return fmt.Sprintf(dsnTpl, m.Host, m.Username, m.Password, m.Database, m.Port, m.SslMode, m.TimeZone)
}