jkwchui

jkwchui

Using AshSqlite as "embedded" database

I am learning AshSqlite and thought there is value in writing a tutorial, where one goes end-to-end in creating the .sqlite, load some data, define the Resources, and finally packaging the application (let’s call it Facts) as a dependency for other applications (let’s call it Consumer). The last step is where I am stuck. (These are probably general Elixir-Ecto questions.)

In Facts, the created sqlite lives inside priv/ as ./priv/facts.sqlite. It is made available to Exqlite inside config.exs. This works fine while developing Facts.

However, when Facts is used as a dependency, its configuration is not brought in.


Question 1: is there a different place inside Facts where the database connections can be configured? Ideally libraries using Facts would be completely oblivious to how the function calls return values, and that it is included the same {:facts, "~> 1.0"} as any other deps.


To get around this temporarily, I pasted the configuration from Facts into Consumer, which I thought was the wrong move. But obviously ./priv/facts.sqlite isn’t available now. So I thought I could point to the database with

"#{:code.priv_dir(:facts)}/priv/facts.sqlite"`

but this doesn’t work because config happens before compile and :code.priv_dir/1 always returns {:error, "bad name"}.


Question 2: how could one point to the innards of a dependency inside config?

First Post!

zachdaniel

zachdaniel

Creator of Ash

Question 1

I believe you can put this kind of information in the init/2 callback of the repo module in question:

Question 2

This is a good question, and I’m not actually sure that you can? As you said, :code.priv_dir(:facts) doesn’t work in that context. Do you have that same experience if its in runtime.exs?

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement