From 25073f13818cb8292e9a26a0fb35a747e43c5b84 Mon Sep 17 00:00:00 2001 From: "arseny.sazanov@gmail.com" Date: Sun, 3 Jul 2022 12:08:24 +0300 Subject: [PATCH] Add RepoByName method --- db/connector/connector.go | 7 +++++++ db/db.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/db/connector/connector.go b/db/connector/connector.go index b239d89..224524d 100644 --- a/db/connector/connector.go +++ b/db/connector/connector.go @@ -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() diff --git a/db/db.go b/db/db.go index 3bd5b7f..663eb49 100644 --- a/db/db.go +++ b/db/db.go @@ -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)