Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:set -XDeriveAnyClass -XDeriveGeneric -XTemplateHaskell
4 changes: 4 additions & 0 deletions bare_shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let pkgs = (builtins.getFlake "nixpkgs").legacyPackages.x86_64-linux;
in
pkgs.mkShell { buildInputs = with pkgs; [ghc cabal-install postgresql postgresql.dev zlib
pkg-config];}
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
packages: .
constraints: ansi-wl-pprint < 1.0.0
allow-newer: base16:base, base16:deepseq, base16:text

tests: true
62 changes: 62 additions & 0 deletions diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

commit b384871b242cef11e717f2671e0128f75887e3b0
Author: remeike <[email protected]>
Date: Mon Aug 5 09:07:59 2024 -0400

Fix regex match operator (#336)

commit e214b75565439461302342083a9bca59894cf34f
Author: Shane <[email protected]>
Date: Tue Jul 30 18:08:25 2024 +0100

Remove `Table Expr b` constraint from `materialize` (#334)

Not only is this not necessary, it can actually act as a barrier to optimisation. The reason I added it was because it seemed like a cheap way to stop someone writing `query' <- materialize query id` — if you return the materialized query from `materialized`, it won't work. Really we would need some sort of `runST` type trick here to do this properly, but that would be too invasive a change.

commit 149ec23c6f32ff677940ca39d6598cfc3a9593bb
Author: Shane <[email protected]>
Date: Mon Jul 15 11:54:22 2024 +0100

Add `aggregate{Just,Left,Right,This,That,Those,Here,There}Table{,1}` aggregators (#333)

These provide another way to do aggregation of `MaybeTable`, `EitherTable` and `TheseTable`s than the existing `aggregate{Maybe,Either,These}Table`.

commit dbda2da7bc94da0b4118be1ff689aab67f2f56ed
Author: Teo Camarasu <[email protected]>
Date: Tue Jul 2 16:41:09 2024 +0100

docs: fix haddock link (#332)

Previously this linked to Prelude.fromIntegral, but we mean Rel8.Num.fromIntegral

commit 6b0721b4ca53f228775501bbe7e56722aec27a47
Author: Shane <[email protected]>
Date: Mon Jul 1 12:56:48 2024 +0100

Expose `listOf` and `nonEmptyOf` (#330)

It was an oversight that these were ever not exported.

commit d8ca92fe85ceec0ff4cf55c9156678bd55a23fc1
Author: Teo Camarasu <[email protected]>
Date: Thu Jun 20 17:28:57 2024 +0100

Fix code block format (#329)

Without the indentation, this doesn't parse properly

commit 21b17334864a2abbeac3f953710f9f0e6ac95f10
Author: Teo Camarasu <[email protected]>
Date: Wed May 29 15:56:49 2024 +0100

docs: remove empty 'where' clause (#327)

This hanging where statement seems like a typo or the ghost of a proper where long gone

commit 6ec03667c472b102f9e447c682cc00c680f1a152
Author: abigailalice <[email protected]>
Date: Wed Apr 3 07:57:50 2024 -0700

Fix some markup in haddocks (#318)

Fixes #315.
38 changes: 19 additions & 19 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ imports throughout this guide::
{-# language TypeApplications #-}
{-# language TypeFamilies #-}

import Prelude
import Prelude hiding (filter)
import Rel8

The Example Schema
Expand Down Expand Up @@ -104,9 +104,9 @@ And similarly, the ``project`` table::
deriving stock (Generic)
deriving anyclass (Rel8able)

To show query results in this documentation, we'll also need ``Show`` instances:
Unfortunately these definitions look a bit scary, but they are essentially just
``deriving (Show)``::
To show query results in this documentation, we'll also need ``Show``
instances: Unfortunately these definitions look a bit scary, but they are
essentially just ``deriving (Show)``::

deriving stock instance f ~ Result => Show (Author f)
deriving stock instance f ~ Result => Show (Project f)
Expand Down Expand Up @@ -161,11 +161,11 @@ can use ``namesFromLabelsWith``, which takes a transformation function.
.. note::

You might be wondering why this information isn't in the definitions of
``Author`` and ``Project`` above. Rel8 decouples ``TableSchema`` from the data
types themselves, as not all tables you define will necessarily have a schema.
For example, Rel8 allows you to define helper types to simplify the types of
queries - these tables only exist at query time, but there is no corresponding
base table. We'll see more on this idea later!
``Author`` and ``Project`` above. Rel8 decouples ``TableSchema`` from the
data types themselves, as not all tables you define will necessarily have a
schema. For example, Rel8 allows you to define helper types to simplify the
types of queries - these tables only exist at query time, but there is no
corresponding base table. We'll see more on this idea later!

With these table definitions, we can now start writing some queries!

Expand All @@ -184,13 +184,14 @@ required knowledge.

To start, we'll look at one of the simplest queries possible - a basic ``SELECT
* FROM`` statement. To select all rows from a table, we use ``each``, and
supply a ``TableSchema``. So to select all ``project`` rows, we can write::
supply a ``TableSchema``. So to select all ``project`` rows, we can write::

>>> :t each projectSchema
each projectSchema :: Query (Project Expr)

Notice that ``each`` gives us a ``Query`` that yields ``Project Expr`` rows. To
see what this means, let's have a look at a single field of a ``Project Expr``::
see what this means, let's have a look at a single field of a ``Project
Expr``::

>>> let aProjectExpr = undefined :: Project Expr
>>> :t projectAuthorId aProjectExpr
Expand All @@ -217,8 +218,8 @@ Haskell values. Studying ``projectAuthorId`` again, we have::
>>> :t projectAuthorId aProjectResult
projectAuthorId aProjectResult :: AuthorId

Here ``Column Result AuthorId`` reduces to just ``AuthorId``, with no
wrappping type at all.
Here ``Column Result AuthorId`` reduces to just ``AuthorId``, with no wrappping
type at all.

Putting this all together, we can run our first query::

Expand Down Expand Up @@ -273,9 +274,9 @@ returned rows. We could write::
where_ $ projectAuthorId project ==. authorId author
return (project, author)

but doing this every time you need a join can obscure the meaning of the
query you're writing. A good practice is to introduce specialised functions
for the particular joins in your database. In our case, this would be::
but doing this every time you need a join can obscure the meaning of the query
you're writing. A good practice is to introduce specialised functions for the
particular joins in your database. In our case, this would be::

projectsForAuthor :: Author Expr -> Query (Project Expr)
projectsForAuthor a = each projectSchema >>= filter \p ->
Expand Down Expand Up @@ -344,8 +345,8 @@ structures. Earlier we saw an example of returning authors with their projects,
but the query didn't do a great job of describing the one-to-many relationship
between authors and their projects.

Let's look again at a query that returns authors and their projects, and
focus on the /type/ of that query::
Let's look again at a query that returns authors and their projects, and focus
on the /type/ of that query::

projectsForAuthor a = each projectSchema >>= filter \p ->
projectAuthorId p ==. authorId a
Expand All @@ -359,7 +360,6 @@ focus on the /type/ of that query::
select conn authorsAndProjects
:: MonadIO m => m [(Author Result, Project Result)]


Our query gives us a single list of pairs of authors and projects. However,
with our domain knowledge of the schema, this isn't a great type - what we'd
rather have is a list of pairs of authors and /lists/ of projects. That is,
Expand Down
4 changes: 4 additions & 0 deletions rel8.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ library
, bytestring
, case-insensitive
, comonad
, containers
, contravariant
, data-textual
, hasql >= 1.6.1.2 && < 1.9
Expand All @@ -43,6 +44,8 @@ library
, scientific
, semialign
, semigroupoids
, template-haskell
, th-abstraction
, text
, these
, time
Expand All @@ -69,6 +72,7 @@ library
Rel8.Expr.Text
Rel8.Expr.Time
Rel8.Tabulate
Rel8.TH

other-modules:
Rel8.Aggregate
Expand Down
1 change: 1 addition & 0 deletions result
4 changes: 1 addition & 3 deletions src/Rel8/Generic/Rel8able.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
{-# language UndecidableInstances #-}

module Rel8.Generic.Rel8able
( KRel8able, Rel8able
( KRel8able, Rel8able(..)
, Algebra
, GRep
, GColumns, gfromColumns, gtoColumns
, GFromExprs, gfromResult, gtoResult
, TSerialize, serialize, deserialize
)
where
Expand Down
2 changes: 1 addition & 1 deletion src/Rel8/Schema/HTable/Label.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{-# language TypeFamilies #-}

module Rel8.Schema.HTable.Label
( HLabel, hlabel, hrelabel, hunlabel
( HLabel(HLabel), hlabel, hrelabel, hunlabel
, hproject
)
where
Expand Down
Loading