Skip to main content

共享包和示例

Prisma 制作的扩展

¥Extensions made by Prisma

以下是我们在 Prisma 构建的扩展列表:

¥The following is a list of extensions we've built at Prisma:

扩大描述
@prisma/extension-accelerate启用 加速,这是一个可在 300 多个位置使用的全局数据库缓存,具有内置连接池
@prisma/extension-read-replicas向 Prisma 客户端添加只读副本支持

Prisma 社区所做的扩展

¥Extensions made by Prisma's community

以下是社区创建的扩展列表。如果你想创建自己的包,请参阅 共享 Prisma 客户端扩展 文档。

¥The following is a list of extensions created by the community. If you want to create your own package, refer to the Shared Prisma Client extensions documentation.

扩大描述
prisma-extension-supabase-rls添加了对 Prisma Supabase 行级安全性的支持
prisma-extension-bark实现物化路径模式,使你可以在 Prisma 中轻松创建树结构并与之交互
prisma-cursorstream添加基于光标的流式传输
prisma-gpt允许你使用自然语言查询数据库
prisma-extension-caching添加缓存复杂查询的能力
prisma-extension-cache-manager使用任何 cache-manager 兼容缓存来缓存模型查询
prisma-extension-random允许你查询数据库中的随机行
prisma-paginate添加对分页读取查询的支持
prisma-extension-streamdal使用 Streamdal 添加对 Code-Native 数据管道的支持
prisma-rbac添加可自定义的基于角色的访问控制
prisma-extension-redis使用 Redis 和 Dragonfly 数据库进行高效缓存和缓存失效的广泛 Prisma 扩展
prisma-cache-extension用于使用 Redis 缓存和使缓存无效的 Prisma 扩展(将支持其他存储选项)
prisma-extension-caslPrisma 客户端扩展利用 CASL 对大多数简单和嵌套查询强制执行授权逻辑。
prisma-emitter-extensionPrisma 扩展,用于基于可配置的监听器在 CRUD 操作上触发事件。

如果你已经构建了一个扩展并希望看到它的特性,请随时通过打开拉取请求将其添加到列表中。

¥If you have built an extension and would like to see it featured, feel free to add it to the list by opening a pull request.

示例

¥Examples

信息

以下示例扩展仅作为示例提供,不提供任何保证。他们应该展示如何使用此处记录的方法创建 Prisma 客户端扩展。我们建议使用这些示例作为构建你自己的扩展的灵感来源。

¥The following example extensions are provided as examples only, and without warranty. They are supposed to show how Prisma Client extensions can be created using approaches documented here. We recommend using these examples as a source of inspiration for building your own extensions.

示例描述
audit-log-context提供当前用户的 ID 作为 Postgres 审核日志触发器的上下文
callback-free-itx添加一种无需回调即可启动交互式事务的方法
computed-fields将虚拟/计算字段添加到结果对象
input-transformation转换传递给 Prisma 客户端查询的输入参数以过滤结果集
input-validation对传递给突变方法的输入参数运行自定义验证逻辑
instance-methods将类似于 Active Record 的方法(如 save()delete())添加到结果对象中
json-field-types对 JSON 列中存储的数据使用强类型运行时解析
model-filters添加可重复使用的过滤器,可以组成模型的复杂 where 条件
obfuscated-fields防止敏感数据(例如 password 字段)包含在结果中
query-logging使用简单的查询计时和日志记录封装 Prisma 客户端查询
readonly-client创建一个只允许读操作的客户端
retry-transactions为具有索引退避和抖动的事务添加重试机制
row-level-security使用 Postgres 行级安全策略来隔离多租户应用中的数据
static-methods向 Prisma 客户端模型添加自定义查询方法
transformed-fields演示如何使用结果扩展来转换查询结果并将 i18n 添加到应用
exists-method演示如何将 exists 方法添加到所有模型
update-delete-ignore-not-found 演示如何将 updateIgnoreOnNotFounddeleteIgnoreOnNotFound 方法添加到所有模型。

更进一步

¥Going further