Skip to content

Commit

Permalink
feature: #270 Attempt to fix by reference error by not storing gorm d…
Browse files Browse the repository at this point in the history
…b in an intermediate variable
  • Loading branch information
akeemphilbert committed Jul 22, 2023
1 parent e4fe23c commit 3312853
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions controllers/rest/global_initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ func SQLDatabase(ctxt context.Context, tapi Container, swagger *openapi3.Swagger
//DefaultProjection setup default gorm projection
func DefaultProjection(ctxt context.Context, tapi Container, swagger *openapi3.Swagger) (context.Context, error) {
api := tapi.(*RESTAPI)
var gormDB *gorm.DB
var err error
gormDB = api.gormConnection
if gormDB != nil {
if api.gormConnection != nil {
//setup default projection if gormDB is configured
defaultProjection, _ := api.GetProjection("Default")
if defaultProjection == nil {
defaultProjection, err = projections.NewProjection(ctxt, gormDB, api.EchoInstance().Logger)
defaultProjection, err = projections.NewProjection(ctxt, api.gormConnection, api.EchoInstance().Logger)
api.RegisterProjection("Default", defaultProjection)

//---- TODO clean up setting up schemas here
Expand Down
8 changes: 4 additions & 4 deletions projections/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ var ContentQuery QueryModifier
var FilterQuery QueryFilterModifier

func NewGORMRepository(ctx context.Context, container weos.Container, name string, schema *openapi3.Schema) (*GORMDB, error) {
gormdb,_ := container.GetGormDBConnection("Default")
logger, err := container.GetLog("Default")
if err != nil {
return nil, err
Expand Down Expand Up @@ -968,14 +967,15 @@ func NewGORMRepository(ctx context.Context, container weos.Container, name strin
}
}

return &GORMDB{
db: gormdb,
tdb := &GORMDB{
schema: schema,
name: name,
logger: logger,
SchemaBuilder: make(map[string]ds.Builder),
keys: make(map[string]map[string]interface{}),
}, nil
}
tdb.db, err = container.GetGormDBConnection("Default")
return tdb, nil
}

//NewProjection creates an instance of the projection
Expand Down

0 comments on commit 3312853

Please sign in to comment.