AshFramework是用于构建Elixir应用程序的声明式、面向资源和可扩展的框架。在Ash中,资源可以对任何东西提供模型,如数据库表、外部API,甚至是自定义代码。
Ash提供了丰富而广泛的工具集,用于与这些资源进行交互,并基于这些资源进行构建。通过为应用程序提供一组资源作为模型,其他工具就能准确地知道如何使用它们,从而使AshGraphql和AshJsoApi这样的扩展能够以最小的配置提供顶级的API。
通过过滤/排序/分页/计算/聚合、pub/sub、策略授权等内置功能,以及一套全面的工具,Ash支持构建自己的扩展,具有无穷可能性。
示例代码
定义资源defmoduleExample.PostdouseAshHq.Resource,data_layer:AshPostgres.DataLayerpostgresdotable"posts"repoExample.Repoedattributesdoattribute:text,:strigdoallow_il?falseedattribute:visibility,:atomdocostraits[oe_of:[:frieds,:everyoe]]ededactiosdoupdate:reactdoargumet:type,Example.Types.ReactioTypedoallow_il?falseedchagemaage_relatioship(:type,:reactios,type::apped)ededrelatioshipsdobelogs_to:author,Example.Userdoallow_il?trueedhas_may:reactios,Example.Reactioeded
评论