Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created December 10, 2021 05:08
Show Gist options
  • Save manakuro/f13f4ae5ee1b2e3c5199bc94d38befad to your computer and use it in GitHub Desktop.
Save manakuro/f13f4ae5ee1b2e3c5199bc94d38befad to your computer and use it in GitHub Desktop.
func (r *userRepository) CreateWithTodo(ctx context.Context, input model.CreateUserInput) (*model.User, error) {
client := WithTransactionalMutation(ctx)
todo, err := client.
Todo.
Create().
Save(ctx)
if err != nil {
return nil, model.NewDBError(err)
}
u, err := client.User.
Create().
SetInput(input).
AddTodos(todo).
Save(ctx)
if err != nil {
return nil, model.NewDBError(err)
}
return u, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment