Skip to content

Commit

Permalink
Made changes according to the review
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadregoti committed Jan 3, 2021
1 parent 34aea81 commit 5e82c8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 4 additions & 6 deletions gateway/modules/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package crud
import (
"context"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -100,11 +99,10 @@ func (m *Module) initBlock(dbType model.DBType, enabled bool, connection, dbName

// GetDBType returns the type of the db for the alias provided
func (m *Module) GetDBType(dbAlias string) (string, error) {
dbAlias = strings.TrimPrefix(dbAlias, "sql-")
if dbAlias != m.alias {
return "", fmt.Errorf("cannot get db type as invalid db alias (%s) provided", dbAlias)
}
return m.dbType, nil
m.RLock()
defer m.RUnlock()

return m.getDBType(dbAlias)
}

// CloseConfig close the rules and secret key required by the crud block
Expand Down
8 changes: 8 additions & 0 deletions gateway/modules/crud/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ func splitConnectionString(connection string) (string, bool) {
}
return "", false
}

func (m *Module) getDBType(dbAlias string) (string, error) {
dbAlias = strings.TrimPrefix(dbAlias, "sql-")
if dbAlias != m.alias {
return "", fmt.Errorf("cannot get db type as invalid db alias (%s) provided", dbAlias)
}
return m.dbType, nil
}
2 changes: 1 addition & 1 deletion gateway/modules/crud/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *Module) Read(ctx context.Context, dbAlias, col string, req *model.ReadR
}

if req.IsBatch {
dbType, err := m.GetDBType(dbAlias)
dbType, err := m.getDBType(dbAlias)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 5e82c8a

Please sign in to comment.