如何将业务逻辑与棱镜逻辑分开

发布于 2025-01-19 12:55:02 字数 642 浏览 2 评论 0原文

我刚刚开始在项目中使用Prisma作为ORM,但是我不确定如何将Prisma查询和逻辑代码与使用Prisma的服务逻辑分开,因为我们无法使用通用存储库方法,我希望为了找到实现这种脱钩的解决方法,有什么想法吗?

这是“应用程序”的一个示例。服务'使用Prisma

>  async findByIdPrisma(applicationId: number):
> Promise<ApplicationModel> {
>     const application = await this.prismaService.application.findUnique({
>       where: { id: applicationId },
>     });
>     if (application) {
>       return application;
>     }
>     throw new DataIsForbiddenOrNotFoundException('Application', {
>       Application: applicationId,
>     });   }

我想实现的解决方案是将这些查询作为函数在单独的存储库中具有完全与此服务完全解耦的功能,谢谢

I have just started using Prisma as an orm, in my project, but I am not sure how to separate the Prisma queries and logic code from the service logic that's using Prisma, since we can't use the generic repositories approach, I would like to find a workaround to achieve this decoupling, any ideas?

this is an example of an 'application. service' using Prisma

>  async findByIdPrisma(applicationId: number):
> Promise<ApplicationModel> {
>     const application = await this.prismaService.application.findUnique({
>       where: { id: applicationId },
>     });
>     if (application) {
>       return application;
>     }
>     throw new DataIsForbiddenOrNotFoundException('Application', {
>       Application: applicationId,
>     });   }

the solution that I want to achieve is having those queries as functions in a separate repository having it totally decoupled from this service, thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文