
The highest tagged major version is
v2.
package
Version:
v0.0.12
Opens a new window with list of versions in this module.
Published: Jun 1, 2023
License: MIT
Opens a new window with license information.
Imports: 14
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
= Database configuration
== Environments
|===
|Env name |Required|Default value
|`DB_DIALECT`
|no
|pgx
|`DB_HOST`
|*yes*
|
|`DB_PORT`
|no
|5432
|`DB_NAME`
|*yes*
|
|`DB_SSL_MODE`
|no
|disable
|`DB_MAX_IDLE_CONNECTIONS`
|no
|5
|`DB_MAX_OPEN_CONNECTIONS`
|no
|15
|`DB_MAX_LIFETIME_IN_MINUTES`
|no
|15
|`DB_USER`
|yes
|
|`DB_PASSWORD`
|*yes*
|
|`SCHEMA_DB_USER`
|no
|env value `DB_USER`
|`SCHEMA_DB_PASSWORD`
|no
|env value `DB_PASSWORD`
|`GOOSE_MIGRATION_DIR`
|no
|/db/migrations
|===
== Конвенция работы с БД из сервисов
. For entities, it is recommended to use the method link:https://gorm.io/docs/conventions.html#TableName[`TableName`] and extend from link:base-entity.go[BaseEntity]
+
[sourse,go]
====
type MyEntity struct {
BaseEntity
}
func (MyEntity) TableName() string {
return "db-table-name"
}
====
include::naming-policy.adoc[]
include::TODO.adoc[]
Documentation
¶
View Source
var (
ErrCreateInstance = errors.New("DB instance creation error")
ErrDbMigration = errors.New("database migration error")
ErrConnectDB = errors.New("database connection error")
)
type BaseEntity struct {
UID *uuid.UUID `gorm:"column:uid; type:uuid; primaryKey; default:uuid_generate_v4()"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at"`
}
type Config struct {
Dialect string `env:"DB_DIALECT" envDefault:"pgx"`
Host string `env:"DB_HOST,notEmpty"`
Port int `env:"DB_PORT" envDefault:"5432"`
Name string `env:"DB_NAME,notEmpty"`
SslMode string `env:"DB_SSL_MODE" envDefault:"disable"`
MaxIdleConnections int `env:"DB_MAX_IDLE_CONNECTIONS" envDefault:"5"`
MaxOpenConnections int `env:"DB_MAX_OPEN_CONNECTIONS" envDefault:"15"`
MaxLifetimeInMinutes int `env:"DB_MAX_LIFETIME_IN_MINUTES" envDefault:"15"`
GooseMigrationDir string `env:"GOOSE_MIGRATION_DIR" envDefault:"/db/migrations"`
}
type Credential struct {
User string `env:"DB_USER"`
Password string `env:"DB_PASSWORD"`
}
type DB struct {
Config *Config
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.