adamkali / adamkali/Tavern-Backend

Make DB Requests To Be more convienient

Aberta
#4 0 comentários 0 reações 1 responsável Reivindicada por @adamkali Ver no GitHub
enhancement good first issue Nice To Have Research
Linguagem predominante
Go
Estrelas
2
Forks
0
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

```
// TODO: Make DB Requests To Be more convienient
```

https://github.com/adamkali/Tavern-Backend/blob/40addcbb17c9f3ec0b39e10e2862b5a24d7f3c56/controllers/UserController.go#L23

I would like to add a Repository Struct like Csharp's Linq. This will help with database querying and help in debugging and avoiding errors and bugs. See below for a rough idea:
```golang
type ModelRepository[T IData] struct {
db gorm.DB
model T
models []T
}

func NewModelRepository[T IData](db grom.DB) {
return ModelRepository[T]{
db,
T.NewData().(T),
[]T{},
}
}

func (repo ModelRepository[T IData]) Sanitize(m T) {
// Clear out the data for every call.
}

```

In this way we could impliment:
```golang
type UserRepository = ModelRepository[models.User]
func NewUserRepository(db gorm.DB) {
return NewModelRepository[models.User](db)
}
```

Then the following call:
```golang

res := c.H.DB.Preload("PlayerPrefrences").Where("SOME WHERE CLAUSE").First(&user)

```

could then become something like:
```golang
var res models.User
err := repo.SomeWhereClause(&res)
```

I think this will be more beneficial in the long run, as we would only need to instantiate the new repo in the construction of the controller:
```golang

type UserController struct{ H BaseHandler[models.User] }

func NewUserController(DB *gorm.DB) *UserController {
return &UserController{
H: *NewHandler(DB, models.User{}, "User"),
}
}

```
becomes:
```golang

type UserController struct{ H BaseHandler[models.User] }

func NewUserController(DB *gorm.DB) *UserController {
return &UserController{
H: *NewHandler(NewUserRepo(db), models.User{}, "User"),
}
}
```

Obviously this will need to be tested and vetted. First push Bëor branch as production, and then `git checkout -b "Beor v1/RepositoryAbstraction"` can be made and pushed in a later version. Probably Bëor v1.1.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Start at controllers/UserController.go around line 23 and inspect how GORM requests are currently made. Review the proposed generic repository and controller-construction changes; the issue is complete only when the repository API is agreed, implemented, and tested across the affected database calls.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
go
Domínio
backend, database
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
20/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.