Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Struct #1

Open
emmaLP opened this issue Aug 5, 2022 · 2 comments
Open

Single Struct #1

emmaLP opened this issue Aug 5, 2022 · 2 comments

Comments

@emmaLP
Copy link
Collaborator

emmaLP commented Aug 5, 2022

Really like the idea of this and really helps with duplicate code for across multiple tables (structs). Could the repository code handle just sue the db entity instead of converting between a domain struct and the db struct?

@Ompluscator
Copy link
Owner

Hi @emmaLP .

Thank you for asking.
Yes, that is possible to do it, although I like to make a cut between domain model and DTO. But, yes, it is possible to do that :)

emmaLP added a commit to emmaLP/gorm-generics that referenced this issue Nov 25, 2022
@Philiphil
Copy link
Contributor

Hi, if I have understood your need correctly, there's a way you can already achieve this

when instantiating the new repo you can use twice the model
repo := gorm_generics.NewRepository[Model, Model](db)

and in your model you can implement toEntity and fromEntity this way

func (m Model) ToEntity() Model {
	return m    
} 
func (m Model) FromEntity(m Model) interface{} {
	return m
}

Then it will work with only one single struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants