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

Why is my data not being returned in date order? #16

Open Cleop opened 5 years ago

Cleop commented 5 years ago

I have a table which I am getting all of the information on (using .all). I need to order this data by date as it is currently not being displayed in date order. I can't work out what is determining the order but it's not date. I took a look at the .all code and noticed that it looks like it should already be being returned in descending date order which is exactly what I need:

https://github.com/dwyl/alog/blob/4cbf9d7f3399a665a9b59c5ed0cb96a0e27afc59/lib/alog.ex#L187

Does anyone know why my data is not being returned in date order?

My code is literally just: Venue.all(), no other manipulating of the data.

Danwhy commented 5 years ago

The order_by clause is part of the subquery (that gets the unique, most recent entry), so the order isn't carried through when we make our second query (to get non-deleted entries).

The inserted_at timestamp should be available on each item you get from the all query, so the easiest thing to do would be to Enum.sort_by(& &1.inserted_at) after getting the results, but I agree it would be nice to be able to specify clauses to pass to our all function that we can add to the sql query.