dwyl / alog

🌲 alog (Append-only Log) is an easy way to start using the Lambda/Kappa architecture in your Elixir/Phoenix Apps while still using PostgreSQL (with Ecto).
GNU General Public License v2.0
15 stars 2 forks source link

Should All function be able to take queries? #29

Open RobStallion opened 5 years ago

RobStallion commented 5 years ago

Should we be able to pass a query to the all function?

Currently all gets all the the distinct :entry_ids from the database, orders the results and removes any values where deleted is true.

This works well but does not allow us to do any further database queries.

For example, if you wanted to retrieve a list of all users from a user table who were under 50. With Ecto.Repo you would be able to pass in a query that looks something like...

query = from(u in user, where: u.age < 50)
Repo.all(query)

The database does all the logic and returns only the data you need.

With the current all in alog we would need to retrieve all users and then filter them ourselves in app.

@danwhy @nelsonic any thoughts/suggestions on how we can extent the all function to all users to pass in any query but still keep/use the current query?

Danwhy commented 5 years ago

My first thoughts are that we can either use another subquery when a query is given as a parameter, or we reduce the queries into a single one, similar to what we're doing with the get_by function.

We'd have to try them out to see if either of them actually work/which is better though

nelsonic commented 5 years ago

@RobStallion great question and thank you for capturing it in this issue! 👍 We should attempt to make our all/1 function as similar to Ecto's Repo.all/1 as possible to minimise the friction to adoption or "cognitive load" people have when learning how to query an append-only log.

As @Danwhy says, we should try this out and see how simple we can make it. Ideally all queries in alog should be Ecto Queryables so that they can be chained.