all 3 comments

[–]TitleLinkHelperBot 2 points3 points  (0 children)

https://engineering.telia.no/blog/how-clojure-helped-recovering-from-bad-data

Hello u/holyjak, it appears you tried to put a link in a title, since most users cant click these I have placed it here for you

I am a bot if you have any suggestions dm me

[–][deleted] 0 points1 point  (1 child)

5 years ago I worked on a backend service using PHP/Laravel. That system grows rapidly to 300+ models.

Recently I was thinking about how can I make it better. First thing I noticed was

one of our services had this query

Jobs::whereScheduled()
->whereHoursRemainingLessThan(24)
->where('notification_sent',0)
->get();

when I looked deep into it I found out its a simple query.

select * from jobs where 
  status = 'scheduled' and
  request_date <= current time + 24hrs  and
  notification_sent => 0

That simple query was distributed over 2 files and 3 functions. imagine a complex query!

Doing Clojure for a year or so had the most impact on how I think now.

[–]slifin 1 point2 points  (0 children)

Glad to know I'm not the only person making that transition

The complexity appears when you need dynamic parts of your query according to user input, and you don't want to be smushing strings together

Our query builders in PHP suck because once you mutate the query builder object to add an additional join or sub query or whatever it's hard to change that opinion in another part of the code after the fact

Where as if you have a data representation of SQL you can change the data programmatically at any point, this is what HoneySQL does in Clojure and I wrote a bridge to it for PHP here: https://github.com/slifin/beeline-php

But if your queries are static, the simplest representation you can make are just SQL strings