TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

FunSQL.jl – Julia library for compositional construction of SQL queries

25 pointsby andreypoppover 3 years ago

1 comment

andreypoppover 3 years ago
Given the recent posts about compile-to-SQL languages, I thought I&#x27;d post here a link to FunSQL.jl which is another interesting point in the design space and which, I think, has quite a few really useful design decisions.<p>The library presents an API of combinators for query construction but it&#x27;s totally possible to build a concrete syntax around it (in fact I did it for my port in OCaml). But syntax isn&#x27;t really this important (it is of course) but the compositional semantics FunSQL.jl provides:<p>1. Query combinators can be composed together in any order (if they are &quot;compatible&quot;) unlike SQL where structure SELECT .. FROM .. WHERE .. is rigid:<p><pre><code> from users where is_active select username </code></pre> (also `from` being the first combinator makes code completion much powerful).<p>2. The way FunSQL.jl treats `group by` as just another kind of namespace, aggregates are then specified as just expressions under this namespace:<p><pre><code> from users as u join (from comments group by user_id) as c on c.user_id = u.id select u.username, c.count() as comment_count, c.max(created_date) as comment_last_created_date </code></pre> In the example above the `c` subrelation is grouped by `user_id` but it doesn&#x27;t specify any aggregates - they are specified in the `select` below so you have all selection logic co-located in a single place.<p>This is a really useful feature, from my point of view, as it&#x27;s allows you to construct re-usable query fragments first and then combine them to build complete quries.<p>3. In other aspects FunSQL.jl is really close to SQL which I think is a big plus as well — familiriaty.