TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

25 点作者 andreypopp超过 3 年前

1 comment

andreypopp超过 3 年前
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.