Introduction

Preface

Relational databases are a common and powerful approach to storing and processing information. Based on the solid foundation of relational algebra, they are efficient, resilient, well-tested, and full of useful features.

However, they all share the same weakness: They all use an antiquated programming interface called SQL.

While SQL was clever and innovative at the time of its conception, today we can look back on its design and see it has many fundamental mistakes, which make SQL incompatible with our contemporary notions of how a programming language should look and work.

As data becomes ever more important to the world of computation, so grows the appeal of a better solution. This need for an alternative inspired us to create the Preql programming language.

Preql

Preql is a new programming language that aims to replace SQL as the standard language for programming databases.

These are big shoes to fill. Here is how Preql intends to do it:

Preql compiles to SQL

Like SQL, Preql is guided by relational algebra, and is designed around operations on tables.

In Preql, table is a built-in type that represents a database table, and all table operations, such as filtering, sorting, and group-by, are compiled to SQL.

That means Preql code can run as fast and be as expressive as SQL.

Preql supports multiple targets, including PostgreSQL, MySQL and SQLite. See features for a complete list.

Preql is interpreted

Not everything can be done in SQL. Control-flow constructs like for-loops, or downloading a remote JSON file, aren’t possible in every database implementation.

Some things, such as first-class functions, or reflection, aren’t possible at all.

Whenever your Preql code can’t be compiled to SQL, it will be interpreted instead.

Being interpreted also lets Preql adopt advanced concepts, like “everything is an object”, support for eval(), and so on.

That means in Preql you can do anything you could do in Python or Javascript, even when SQL can’t.

Better syntax, semantics, and practices

Preql’s syntax is inspired by javascript. It’s relatively concise, and familiar to programmers.

It integrates important ideas like Fail-Early, and the Principle Of Least Astonishment.

The code itself is stored in files, instead of a database, which means it can be version-controlled (using git or similar)

Preql also comes with an interactive prompt with auto-complete.

Escape hatch to SQL

There are many dialects of SQL, and even more plugins and extensions. Luckily, we don’t need to support all of them.

Preql provides the builtin function SQL(), which allows you to run arbitrary SQL code, anywhere in your Preql code.

Conclusion

Preql’s design choices allow it to be fast and flexible, with a concise syntax.

Preql adopts the good parts of SQL, and offers improvements to its weakest points.

Where to go next?