spicychickensauce
I’m evaluating migrating an existing application to ash and it’s looking pretty good so far.
However, I got stuck at this: My app currently supports both sqlite and postgres, configured via a compile time setting. (I need sqlite support because my app is also bundled on android, postgres is used on servers)
I cannot figure out how to make that work with ash.
The problem is in the resources. I tried this:
if App.Config.use_sqlite?() do
use Ash.Resource,
domain: App,
data_layer: AshSqlite.DataLayer
else
use Ash.Resource,
domain: App,
data_layer: AshPostgres.DataLayer
end
# same conditional for the `postgres` and `sqlite` expressions
actions do
...
However, I get a compile error:
error: undefined function actions/1 (there is no such import)
│
12 │ actions do
This is very weird, since when I manually comment out the appropriate use it compiles just fine.
What is happening here? Why does this conditional compilation logic not work with ash?
It used to work just fine when I did that in my ecto repo to configure the appropriate adapter…
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Hey, I know this has been discussed ad nauseum, but I couldn’t find a definitive answer or at least some consensus around this, so let me...
New
I don’t suppose you can lazy load a library depending on runtime data? For example if it’s a certain user they can lazy load ‘library A’ ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #code-sync
- #exunit
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #ai
- #authentication
- #elixirconf-us
- #umbrella
- #full-time-contract
- #blog-post
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-eu
- #distillery
- #security
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
use
mix ash.gen.base_resource MyApp.Resourceand then modify it to look something like this:spicychickensauce
Thank you!
This got me one step closer.
However, now I’m getting a similar error a bit later here:
This is with
use_sqlite?() == false, with true I get the error onpostgres do.Maybe I need some more macro magic? I just don’t understand how this unreachable code path can cause a compile error, that function doesn’t need to be defined in that branch!
spicychickensauce
I got it working by doing:
A bit weird, since the
use MyApp.Resourceshould already have imported those definitions, at least for the branch that is compiled.Anyway, that seems to work and isn’t too bad..
spicychickensauce
Now ideally I could also get rid of the duplication inside the
postgresand thesqliteblock.They will have to be kept in sync and as far as I can tell the options that each support is pretty much identical.
I’m not that familiar with macros, but I’m guessing this could be done via a macro?
spicychickensauce
Ok, this was easier than anticipated.
I created a macro like this:
And can use it like this:
I’m sure this will shoot me in the foot at some point when I need to use a feature that only exist in postgres, but for now it seems to work nicely
zachdaniel
Simpler would be this:
You can use the
postgresandsqliteextensions multiple times, and can add it as an extension without making it the data layer so that when you have special sqlite or postgres specific things in a resource, you can just dopostgres do ...and not includetable.spicychickensauce
Thanks, the
extension_to_addpart might be useful!However, I’ve also got
referencesblocks,identity_index_namesandcustom_indexesetc. in thosesqlite_or_postgresblocks.So with your proposed approach, it seems like I’d have to define all of these inside the
use MyApp.Resource, table: ..., etc. That doesn’t seem like a good approach?zachdaniel
Yeah, that’s a good point
. You could do it your way, and then with the addition of adding both extensions, you could do custom things in
postgresandsqliteblocks respectively.spicychickensauce
Great, then I’ll go with that. Seems the most flexible and DRY approach.
Thank you very much for the help!