zachdaniel

zachdaniel

Creator of Ash

@jimsynz just launched an epic new extension for Ash! It allows you to create rich mix tasks for calling your resource actions directly from the command line.

Its only just had its first release, so there will probably be bugs here and there, but honestly this think slaps and so far it has Just Worked™ in my usage.

Check out the docs for more: README — ash_ops v0.2.4

Here is a teaser image:

Which would give you:

mix tunez.music.create_album and mix tunez.music.list_albums mix tasks. If you really want your mind blown, try out the --filter option on list tasks, and the --format option on any of them :exploding_head:

And there is a demo video in the latest Ash Weekly newsletter: Ash Chronicle | Zach Daniel | Substack

Showing Posts 1 to 6

matthewsinclair

matthewsinclair

This :point_up: is awesome! I have a CLI/REPL utility that I have been hacking around with for a while now, and I have an idea for an Ash-compatible extension for it at the back of my mind. I will see if I can quickly connect the two …

BTW: This might not be to everyone’s taste. It’s potentially very ropey Elixir code, so don’t expect too much! The motivation for it was twofold: a) to help me learn Elixir, and b) to have a simple way to implement the command pattern from a CLI/REPL so that I could test my code as I was building it. As they say, #ymmv. :pray:

Stefano1990

Stefano1990

This is absolute fire and @jimsynz is the MVP.

matthewsinclair

matthewsinclair

Ok, I must be being really dumb. Where does the mix_tasks... bit go? I ran the install via mix igniter.install ash_ops and then I have tried to put that inside the Ash Domain, the Ash Resource, in mix.exs. This looks so simple from the docs, what am I doing wrong?

This seemed the most obvious place to put it given the instructions said “Example: Defining the following action in your domain”

So I did this:

defmodule Myapp.Accounts do
  use Ash.Domain, otp_app: :myapp, extensions: [AshAdmin.Domain]
  ...
  mix_tasks do
    list Myapp.Accounts.User, :list_users, :read
  end
end

But that generates a compile error. :thinking_face:

matthewsinclair

matthewsinclair

Aha. I worked it out. I needed to add AshOps to :extensions like this:

defmodule Myapp.Accounts do
  use Ash.Domain, otp_app: :myapp, extensions: [AshAdmin.Domain, AshOps]

Now the mix task is available:

mix help | grep myapp
mix myapp.accounts.list_users     # Query for `Myapp.Accounts.User` records using the `read` action

Cool!

matthewsinclair

matthewsinclair

Ok, the next question is how to map these resource actions onto the mix tasks? For example, consider this:

defmodule Myapp.Accounts do
  use Ash.Domain, otp_app: :icpzero, extensions: [AshAdmin.Domain, AshOps]

  admin do
    show? true
  end

  resources do
    resource Myapp.Accounts.Token

    resource Myapp.Accounts.User do
      define :add_user_to_team, action: :add_to_team
      define :get_user_by_email, action: :read, get_by: :email
      define :get_user_by_id, action: :read, get_by: :id

      define :register_with_password, action: :register_with_password
      define :set_role, action: :set_role
      define :set_name, action: :set_name
    end

    resource Myapp.Accounts.Team do
      define :create_team, action: :create
    end
  end

  mix_tasks do
    list Myapp.Accounts.User, :list_users, :read
  end
end

What’s the syntax for mapping those Resource commands that take a parameter onto mix tasks?

matthewsinclair

matthewsinclair

More here: Slack

— All posts loaded —

Where Next? Top

Trending in News & Updates Top

sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
kip
I’m a bit excited to announce that Localize and friends are now at release 1.0. Even though it’s a 1.0 release, it stands on 8 years of w...
New
bartblast
I’ll be using this thread to share Hologram patch release announcements. Minor releases will continue to get dedicated threads with blog ...
New
bartblast
Hologram v0.11 is out! Two headline features this release. First, Elixir regexes now run in the browser. They were server-only until now,...
New
nseaSeb
Just published search_ash 0.5.0 (with search_core 0.4.0) on Hex. What’s new: synonyms You can now declare a synonym dictionary per lang...
New
mudasobwa
MdexMultilineCells is an MDEx plugin enabling multi-line cells in Markdown tables with full inline/block Markdown rendering and automati...
New
sorenone
This release unifies configuration for queues, repos, and services, swaps opaque timing integers for readable durations, and backports pe...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews