Skip to content

Commit

Permalink
Add RepoByName method
Browse files Browse the repository at this point in the history
  • Loading branch information
imperiuse committed Jul 3, 2022
1 parent 0460de1 commit 25073f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions db/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func (c *connector[C]) Connection() db.PureSqlxConnection {
func (c *connector[C]) Repo(dto db.DTO) db.Repository {
var repoName = dto.Repo()

return c.RepoByName(repoName)
}

// RepoByName - return db.Repository based repoName
// if cfg.IsEnableValidationRepoNames() == true => do validation action too)
// if cfg.IsEnableReposCache() == true => use cache.
func (c *connector[C]) RepoByName(repoName db.Table) db.Repository {
if c.cfg.IsEnableValidationRepoNames() {
c.mV.RLock()
defer c.mV.RUnlock()
Expand Down
2 changes: 2 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type (
// Repo[I ID, D DTO]() gRepository[I, D] // refactor to this NOW try use this ->
// repository.NewGen[I, DTO]](connector) -> return GRepository

RepoByName(Table) Repository

AutoCreate(context.Context, DTO) (int64, error)
AutoGet(context.Context, DTO) error
AutoUpdate(context.Context, DTO) (int64, error)
Expand Down

0 comments on commit 25073f1

Please sign in to comment.