SuperAPI AI 工具集

ash-framework

编程与开发

查看项目

更新于 10-15 22:16

技能介绍

用途:在考虑、采用或使用 Elixir 的 Ash Framework 时提供规范指引,适用于新建 Ash 项目或大规模重构前。

主要能力与规则:资源必须用 use Ash.Resource 定义,不手写协议;动作需显式定义,不盲目依赖默认 [:read, :create];含敏感数据的资源必须写 policies 授权块;写入使用 Ash.Changeset.for_create/3 与 for_update/3,不直接改结构体;迁移先运行 mix ash_postgres.generate_migrations,再 mix ash_postgres.migrate;用 mix compile 确认无 Spark.Error.DslError。

使用方式:在 mix.exs 加入 {:ash, "~> 3.0"} 与 {:ash_postgres, "~> 2.0"};Repo 改为 use AshPostgres.Repo, otp_app: :my_app;定义 Domain 与 Resource,配置 postgres 的 table 与 repo,声明 attributes、relationships、actions、policies;通过 Domain.create!/read! 等 API 验证。查询过滤用 ^ 安全插值,禁止字符串拼接;大结果集用 keyset 分页 Ash.Query.page(after: ...)。

集成:AshPhoenix 用于 LiveView 表单,AshJsonApi 暴露 JSON:API 路由,聚合用 aggregates 块,校验用动作层 validate 或自定义 Ash.Resource.Validation。错误处理需匹配 Ash.Error.Forbidden、Ash.Error.Query.NotFound 等具体类型。

限制:资料未提供版本兼容细节、性能数据、收费信息与完整 API 参考,相关文档需另行查阅。