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:

Where Next?

Popular in Libraries Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement