SQL Builders: Advanced Joins

Episode #322 • Apr 21, 2025 • Subscriber-Only

We close out our series on SQL query building with a library that can generate some seriously complex queries that select, join, group, aggregate, and filter data across tables. And we show how it can all play nicely with SQL strings by introducing a safe interface to SQL via a custom string interpolation.

Previous episode
SQL Builders: Advanced Joins
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Brandon

We have now implemented a powerful syntax for representing joins in our query builder, and we are able to preserve the type information of each table involved so that we can write SELECT, WHERE and ORDER BY clauses in a type-safe manner. It’s honestly pretty incredible how quickly we were able to get things working, and it’s all thanks to all of the infrastructure we’ve built in previous episodes, as well as the amazing parameter packs feature in modern Swift.

Stephen

Let’s now push things even further. As we saw in last episode, the power of joins really starts to shine when it comes to aggregating data across joins. This is what allowed us to do things like selecting all lists from the database, along with a comma-separated list of the titles of reminders in each list. Another advanced query we previously considered was to select all lists from the database, along with a count of the reminders in each list.

Let’s see what it takes to write such advanced queries with our builder.

Aggregates across joins


References

Downloads

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 71 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing