Skip to content

Instantly share code, notes, and snippets.

@alexmingoia
Created November 24, 2020 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmingoia/f059d832481a1bad98a58b7651876dcd to your computer and use it in GitHub Desktop.
Save alexmingoia/f059d832481a1bad98a58b7651876dcd to your computer and use it in GitHub Desktop.
Selda Crash
{-# 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