All Projects → KMahoney → squee

KMahoney / squee

Licence: MIT License
A Typed, Composable Database Query Language

Programming Languages

haskell
3896 projects
emacs lisp
2029 projects

Projects that are alternatives of or similar to squee

google-cloud-rust
No description or website provided.
Stars: ✭ 148 (+42.31%)
Mutual labels:  experimental
swirlr-wasm
willdady.github.io/swirlr-wasm/
Stars: ✭ 21 (-79.81%)
Mutual labels:  experimental
mimstris
A falling block puzzle game created using React and Redux.
Stars: ✭ 129 (+24.04%)
Mutual labels:  experimental
docs-lovelace
Documentation for Home Assistant Experimental UI: Lovelace
Stars: ✭ 42 (-59.62%)
Mutual labels:  experimental
ember-named-yields
Named Yields for Ember Components
Stars: ✭ 17 (-83.65%)
Mutual labels:  experimental
html-over-dns
An experiment to host a website with the content served over DNS.
Stars: ✭ 29 (-72.12%)
Mutual labels:  experimental
monolithic.nvim
Neovim plugin to open multiple files in one buffer
Stars: ✭ 35 (-66.35%)
Mutual labels:  experimental
staticfuzz
Memories which vanish
Stars: ✭ 15 (-85.58%)
Mutual labels:  experimental
stucco
An experimental adaptive UI toolkit.
Stars: ✭ 31 (-70.19%)
Mutual labels:  experimental
bio-pipeline
My collection of light bioinformatics analysis pipelines for specific tasks
Stars: ✭ 60 (-42.31%)
Mutual labels:  experimental
PocketAI
Addon compatible AI plugin for PocketMine-MP
Stars: ✭ 25 (-75.96%)
Mutual labels:  experimental
oxc
The first C compiler written in Rust.. mostly unworking.
Stars: ✭ 40 (-61.54%)
Mutual labels:  experimental
OnceBuilder
OnceBuilder - managment tool, mange projects, templates, plugins in one place.
Stars: ✭ 18 (-82.69%)
Mutual labels:  experimental
r3
R3-OS — Experimental static (μITRON-esque) RTOS for deeply embedded systems, testing the limit of Rust's const eval and generics
Stars: ✭ 87 (-16.35%)
Mutual labels:  experimental
notable-insiders
A repository containing experimental releases of Notable.
Stars: ✭ 131 (+25.96%)
Mutual labels:  experimental
HoneyBEE
HoneyBEE is a Minecraft server implementation written in go, with help from wiki.vg (huge thanks to them), that aims to be fast by utilising go-routines and being optimised for a low cpu/ram footprint. (Pre-Alpha)
Stars: ✭ 22 (-78.85%)
Mutual labels:  experimental
nuxt-realworld
🛠 Built a Example App of RealWorld with Nuxt & Composition API ⚗️
Stars: ✭ 127 (+22.12%)
Mutual labels:  experimental
sling-whiteboard
Apache Sling Whiteboard - testing ground for new ideas
Stars: ✭ 37 (-64.42%)
Mutual labels:  experimental
Verdant
An experimental tool that stores and visualizes local versioning in JupyterLab
Stars: ✭ 128 (+23.08%)
Mutual labels:  experimental
traffic-prediction
Predict traffic flow with LSTM. For experimental purposes only, unsupported!
Stars: ✭ 47 (-54.81%)
Mutual labels:  experimental

Squee: A Typed, Composable Database Query Language

Squee is an experimental language that breaks relational queries down in to composable functions that can be fully inferred with a few extensions to Hindley Milner. It compiles to SQL and so can be used with relational databases.

WARNING: Squee is EXPERIMENTAL and INCOMPLETE. Don't use this for anything important!

Docs

Rationale

As much as I love languages with a good type system, integrating types with relational querying is often a weak point. It can be complicated, clunky, and result in poor error messages.

Squee's type system has been designed to handle relational concepts and give good, understandable error messages (WIP - error messages are currently terrible).

Unlike SQL, Squee breaks queries down in to composable parts so you can define and re-use joins, maps and filters across your code.

Some Quick Examples

Given a PostgreSQL database with the following definition:

CREATE TABLE example (a int not null, b text not null);
INSERT INTO example VALUES (1, 'example1'), (2, 'example2');

CREATE TABLE join_example (a int not null, c text not null);
INSERT INTO join_example VALUES (1, 'join_example1'), (2, 'join_example2');

Squee will introspect the database and make tables available:

SQUEE> example

: [{a: ~int4, b: ~text}]

| a | b        |
+---+----------+
| 1 | example1 |
| 2 | example2 |

SQUEE> join_example

: [{a: ~int4, c: ~text}]

| a | c             |
+---+---------------+
| 1 | join_example1 |
| 2 | join_example2 |

Queries can be built out of map, filter, order, natjoin, join and aggregate:

  • map : ({α} → {β}) → [{α}] → [{β}]
  • filter : ({α} → ~bool) → [{α}] → [{α}]
  • order : (Comparable β) ⇒ ({α} → β) → [{α}] → [{α}]
  • natjoin : ({γ} = {α} ⋈ {β}) ⇒ [{α}] → [{β}] → [{γ}]
  • join : ({α} → {β} → ~bool) → ({α} → {β} → {γ}) → [{α}] → [{β}] → [{γ}]
  • aggregate : ({β} = Agg {γ}) ⇒ ({α} → {β}) → [{α}] → [{γ}]

The types are explained in the language docs.

The filter function can be abstracted and used in multiple queries:

SQUEE> example | filter (\t -> t.a = 1)

: [{a: ~int4, b: ~text}]

| a | b        |
+---+----------+
| 1 | example1 |

SQUEE> def filterA1 := filter (\t -> t.a = 1)

filterA1 : [{a: ~int4, ..α}] → [{a: ~int4, ..α}]

SQUEE> filterA1 example

: [{a: ~int4, b: ~text}]

| a | b        |
+---+----------+
| 1 | example1 |

SQUEE> filterA1 join_example

: [{a: ~int4, c: ~text}]

| a | c             |
+---+---------------+
| 1 | join_example1 |

as well as the natjoin function:

SQUEE> example | natjoin join_example

: [{a: ~int4, b: ~text, c: ~text}]

| a | b        | c             |
+---+----------+---------------+
| 1 | example1 | join_example1 |
| 2 | example2 | join_example2 |

SQUEE> def joinExample := natjoin join_example

joinExample : ({β} = {a: ~int4, c: ~text} ⋈ {α}) ⇒ [{α}] → [{β}]

SQUEE> example | filterA1 | joinExample

: [{a: ~int4, b: ~text, c: ~text}]

| a | b        | c             |
+---+----------+---------------+
| 1 | example1 | join_example1 |

The queries can be exported to other languages.

Given the file example.squee:

export exportedExample := example
export filteredExportedExample a := example | filter (\t -> t.a = a)

The command squee generate sql-prepare example.squee will generate:

PREPARE exportedExample AS
  SELECT "a","b" FROM "example" AS _t;

PREPARE filteredExportedExample AS
  SELECT "a","b" FROM "example" AS _t WHERE ("a") = ($1);

Since Squee is fully type inferred, it can also generate templates for languages that require type annotations:

squee generate hs-postgresql-simple example.squee:

exportedExample :: Connection -> IO [(Int, String)]
exportedExample connection = do
  query_ connection "SELECT \"a\",\"b\" FROM \"example\" AS _t"

filteredExportedExample :: Connection -> Int -> IO [(Int, String)]
filteredExportedExample connection a = do
  query connection "SELECT \"a\",\"b\" FROM \"example\" AS _t WHERE (\"a\") = (?)" (Only a)

Installation

Requirements:

  • Stack
  • PostgreSQL development libraries (e.g. on Debian/Ubuntu: apt install libpq-dev)
  • ncurses development libraries (e.g. on Debian/Ubuntu: apt install libtinfo-dev)

Clone the repo, and then stack install.

Notes and Limitations

  • Squee doesn't currently handle nulls or nullable fields.
  • Rows have a flat namespace, as opposed to SQL's qualified field names i.e. table.column. A row cannot have duplicate field names because there's no way to disambiguate them.
  • Very few SQL operators/functions are currently available.
  • Only natural and inner joins are currently available. Left/right joins require null handling.
  • The error reporting is currently poor, but quality error reporting is a long-term goal of the project.

Interesting Links

If you know of any similar projects not listed here, please let me know!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].