mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
fix migration
This commit is contained in:
@@ -2,7 +2,6 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -34,14 +33,18 @@ func (e *LoggerHook) AfterQuery(ctx context.Context, qe *pg.QueryEvent) error {
|
||||
func CreateConnection(ctx context.Context, dbUrl string) *pg.DB {
|
||||
opt, err := pg.ParseURL(dbUrl)
|
||||
common.CheckError(err)
|
||||
file, err := os.OpenFile("querys.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
||||
file, err := os.OpenFile("querys.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
||||
common.CheckError(err)
|
||||
QueryLogger := log.New(file, "Query: ", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
conn := pg.Connect(opt)
|
||||
err = conn.Ping(ctx)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
loggerHook := LoggerHook{QueryLogger}
|
||||
conn.AddQueryHook(&loggerHook)
|
||||
db := conn.WithContext(ctx)
|
||||
|
||||
fmt.Println("Successfully connected!")
|
||||
log.Printf("Successfully connected to %s!", dbUrl)
|
||||
return db
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user