You've already forked reloading-manager
fix tpyo
This commit is contained in:
@@ -20,6 +20,10 @@ const (
|
||||
DbPassword Env.EnvironmentVariable = "DB_PASSWORD"
|
||||
)
|
||||
|
||||
type contextKeyType string
|
||||
|
||||
const dbContextKey contextKeyType = "dbcontext"
|
||||
|
||||
type Database struct {
|
||||
Db *pgx.Conn
|
||||
connected bool
|
||||
@@ -50,6 +54,24 @@ func (*Database) DSN(hidePassword bool) string {
|
||||
return fmt.Sprintf("postgres://%s:%s@%s:5432/%s%s", dbUser, dbPassword, dbHost, dbDatabase, extraParams)
|
||||
}
|
||||
|
||||
func NewWithContext(ctx context.Context) context.Context {
|
||||
db := GetNewDatabase()
|
||||
|
||||
return context.WithValue(ctx, dbContextKey, db)
|
||||
}
|
||||
|
||||
func NewFromContext(ctx context.Context) *Database {
|
||||
if ok := ctx.Value(dbContextKey); ok != nil {
|
||||
return ctx.Value(dbContextKey).(*Database)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func WithContext(ctx context.Context, database *Database) context.Context {
|
||||
return context.WithValue(ctx, dbContextKey, database)
|
||||
}
|
||||
|
||||
func GetNewDatabase() *Database {
|
||||
var dbSingleton Database
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ import (
|
||||
|
||||
func (db *Database) Migrate() {
|
||||
sqlDB, err := sql.Open("postgres", db.DSN(false))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
driver, err := postgres.WithInstance(sqlDB, &postgres.Config{
|
||||
MigrationsTable: "schema_migrations",
|
||||
|
||||
Reference in New Issue
Block a user