Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created December 10, 2021 04:41
Show Gist options
  • Save manakuro/876d140358028c960279c9054493e4cb to your computer and use it in GitHub Desktop.
Save manakuro/876d140358028c960279c9054493e4cb to your computer and use it in GitHub Desktop.
package repository
import (
"context"
"golang-clean-architecture-ent-gqlgen/ent"
"golang-clean-architecture-ent-gqlgen/ent/user"
"golang-clean-architecture-ent-gqlgen/pkg/entity/model"
usecaseRepository "golang-clean-architecture-ent-gqlgen/pkg/usecase/repository"
)
type userRepository struct {
client *ent.Client
}
func NewUserRepository(client *ent.Client) usecaseRepository.User {
return &userRepository{client: client}
}
func (r *userRepository) Get(ctx context.Context, id *int) (*model.User, error) {
u, err := r.client.User.Query().Where(user.IDEQ(*id)).Only(ctx)
if err != nil {
return nil, err
}
return u, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment