-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
66a0131
commit 8d967ea
Showing
13 changed files
with
892 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ reg-room-service | |
!cmd/** | ||
target | ||
**/*.swp | ||
config.yaml | ||
config*.yaml | ||
*.http | ||
**/*.jar | ||
api-generator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package entity | ||
|
||
import "time" | ||
import ( | ||
"time" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
type Base struct { | ||
ID string `gorm:"primaryKey; type:varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;NOT NULL"` | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
DeletedAt *time.Time `sql:"index"` | ||
DeletedAt gorm.DeletedAt `gorm:"index"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,57 @@ | ||
package dbrepo | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
aulogging "github.com/StephanHCB/go-autumn-logging" | ||
|
||
"github.com/eurofurence/reg-room-service/internal/repository/database" | ||
"github.com/eurofurence/reg-room-service/internal/repository/database/historizeddb" | ||
"github.com/eurofurence/reg-room-service/internal/repository/database/inmemorydb" | ||
"github.com/eurofurence/reg-room-service/internal/repository/database/mysqldb" | ||
) | ||
|
||
var activeRepository database.Repository | ||
|
||
func SetRepository(repository database.Repository) { | ||
activeRepository = repository | ||
} | ||
|
||
func GetRepository() database.Repository { | ||
if activeRepository == nil { | ||
aulogging.Logger.NoCtx().Error().Print("You must Open() the database before using it. This is an error in your implementation.") | ||
panic("You must Open() the database before using it. This is an error in your implementation.") | ||
} | ||
return activeRepository | ||
} | ||
|
||
func Open(ctx context.Context, variant string, mysqlConnectString string) error { | ||
var r database.Repository | ||
if variant == "mysql" { | ||
aulogging.Info(ctx, "Opening mysql database...") | ||
r = historizeddb.New(mysqldb.New(mysqlConnectString)) | ||
} else { | ||
aulogging.Warn(ctx, "Opening inmemory database (not useful for production!)...") | ||
r = historizeddb.New(inmemorydb.New()) | ||
} | ||
err := r.Open(ctx) | ||
SetRepository(r) | ||
return err | ||
} | ||
|
||
func Close(ctx context.Context) { | ||
aulogging.Info(ctx, "Closing database...") | ||
GetRepository().Close(ctx) | ||
SetRepository(nil) | ||
} | ||
|
||
func Migrate(ctx context.Context) error { | ||
aulogging.Info(ctx, "Migrating database...") | ||
return GetRepository().Migrate(ctx) | ||
} | ||
|
||
func MysqlConnectString(username string, password string, databaseName string, parameters []string) string { | ||
return username + ":" + password + "@" + | ||
databaseName + "?" + strings.Join(parameters, "&") | ||
} |
Oops, something went wrong.