-
-
Save alexmingoia/f059d832481a1bad98a58b7651876dcd to your computer and use it in GitHub Desktop.
Selda Crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedLabels #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Database.Selda | |
import Database.Selda.SQLite | |
data Person | |
= Person | |
{ name :: Text, | |
age :: Int | |
} | |
deriving (Generic) | |
instance SqlRow Person | |
people :: Table Person | |
people = table "people" [#name :- primary] | |
data Pet | |
= Pet | |
{ petname :: Text, | |
owner :: Text | |
} | |
deriving (Generic, Show) | |
instance SqlRow Pet | |
pets :: Table Pet | |
pets = table "pets" [#petname :- primary] | |
main = withSQLite "people.sqlite" $ do | |
createTable people | |
insert_ | |
people | |
[ Person "Velvet" 19, | |
Person "Kobayashi" 23, | |
Person "Miyu" 10 | |
] | |
createTable pets | |
insert_ | |
pets | |
[ Pet "Fluffy" "Miyu" | |
] | |
petsWithOwner <- query $ do | |
person <- select people | |
pet <- leftJoin (\p -> p ! #owner .== person ! #name) $ select pets | |
return (pet :*: person ! #name) | |
liftIO $ print petsWithOwner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment