jechol

jechol

Ash_req_opt - shortcut DSL for attributes and relationships in Ash resources

Hi everyone :waving_hand:

I recently published a small utility library called ash_req_opt, and I wanted to share it here in case it might be useful for others building with Ash Framework.

:light_bulb: What is it?

ash_req_opt is a DSL shortcut for declaring attributes and relationships in Ash resources with commonly used allow_nil? and public? options.

Ash is powerful, but sometimes writing repetitive attribute or belongs_to definitions with the same flags gets a bit tedious. This library simplifies that by providing macros like req, opt, req_belongs_to, etc.

:white_check_mark: Example

defmodule MyApp.User do
  use Ash.Resource, extensions: [AshReqOpt]

  attributes do
    uuid_primary_key :id

    req :email, :string
    req_prv :password_hash, :string
    opt :name, :string
    opt_prv :last_login_at, :utc_datetime

    # fallback to native Ash DSL still works
    attribute :nickname, :string, allow_nil?: true
  end

  relationships do
    req_belongs_to :company, Company
    req_prv_belongs_to :created_by, User
    opt_belongs_to :manager, User
    opt_prv_belongs_to :updated_by, User

    belongs_to :department, Department, allow_nil?: true
  end
end

It’s a small layer, but I hope it helps others too. Feedback, feature suggestions, or improvements are welcome!

:backhand_index_pointing_right: Hex: https://hex.pm/packages/ash_req_opt
:backhand_index_pointing_right: GitHub:

https://github.com/devall-org/ash_req_opt

Where Next?

Popular in Announcing Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19417 141
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement