46

I recalled a seemingly simple task I took on.

We were building a booking system, and I had to figure out how to retrieve bookings by a certain date range.

Upfront, the tasked seemed simple until I realised I had to both figure out the logic and the SQL statements needed to retrieve all bookings within a certain date range in one query.

I ended up drawing a model to help me visualise the various date-range criteria to be satisfied. And used unit tests to help me think through each date range criterion and make sure they were accurate. Some were obviously from paranoia, but better to be safe than sorry...

After that, I had wrote down raw SQL directly into Sequel Pro first to make sure my query logic was accurate too, before translating into something the ORM equivalent. This was when I learned how to define and use variables in SQL. The variables were throw-away code; I just didn't want to have to hard-code the test date-ranges over and over again; minimise chances of spelling errors.

Needless to say, felt my problem-solving skills went up one level after this task. Saw my coding style and unit tests improve. And also the thought processes that go into how to maintain code quality...

Comments
  • 14
    As a full-stack developer who codes mainly in PHP and some Javascript. I find myself being able to do a bit of everything, but very few opportunities to sharpen them and be good at something.

    This task was one example where I felt like a ninja after I solved it... SQL level up!
  • 2
    Good job! :) Sql skills are often underestimated :)
  • 0
    SELECT * from orders WHERE date >= $startDate AND date <= $endDate
  • 0
    @cephei That won't fit use-cases 338 to 345...
Add Comment