Day 3 -

Sept 14th

Stage 1 (Rolling)

15:30 - 16:15

Tyqu: Typesafe SQL Queries in Scala

Language-Integrated Queries (LINQ) is a popular language extension in the .NET framework which allows to generate and execute database queries. It embeds the queries within application code, providing a convenient and type safe API. In other languages including Scala, people have been striving for a similar solution for many years, but it has proven difficult to implement without modifying the language itself.

Tyqu is a LINQ-like Scala library for generating and executing SQL queries against a relational database with the guarantee of type safety for both the generated queries as well as the retrieved data. It enables users to write queries in a familiar functional style operating on nested data, which are automatically translated to relational queries. Tyqu makes heavy use of the latest Scala 3 features such as match types, type-level operations, and a new meta-programming framework. Thanks to that, it provides a more convenient interface, requiring less boilerplate code compared to other popular libraries such as Slick or Quill.

Thanks to a unique mix of compile-time checks and runtime code generation, we have managed to keep Tyqu farily simple and lightweight. To guarantee type safety, all necessary information about a query is represented within its data type. Thus, data accesses are checked statically by the Scala compiler even though the queries themselves are not generated yet. Moreover, we benefit from full code editor support, including suggestions for column names, even when selecting complex named expressions.

In this talk we will introduce the library’s API, including a live demo. Afterwards, we will discuss some of the internal architecture and the challenges that we have encountered while designing it.

Martin Kučera

Besides Scala and other cool programming languages, I also have a strong passion for databases and data processing. I earned my bachelor’s degree in computer science at CTU Prague and my master’s at ETH Zurich. I had the incredible opportunity to complete my master’s thesis at EPFL under the guidance of Martin Odersky. This collaboration led to the development of Tyqu, a type-safe database access Scala library.

In addition to my academic pursuits, I have also gained valuable experience as a backend web developer at manGoweb, and I have worked on a distributed graph processing system at Oracle Labs.

I am excited to be part of Scala Days Madrid. I look forward to demonstrating Tyqu and sharing my experience with applying new Scala 3 features such as structural refinements, match types, and macros in a novel database library.

Subscribe

Join our conference

Subscribe and follow @ScalaDays on Twitter for the latest conference updates.