22{- cabal:
33 build-depends: base >= 4, beam-core, beam-duckdb, duckdb-simple, time, text
44-}
5-
65{-# LANGUAGE DeriveAnyClass #-}
76{-# LANGUAGE DeriveGeneric #-}
87{-# LANGUAGE ExplicitForAll #-}
98{-# LANGUAGE FlexibleInstances #-}
9+ {-# LANGUAGE MultiParamTypeClasses #-}
1010{-# LANGUAGE OverloadedStrings #-}
1111{-# LANGUAGE StandaloneDeriving #-}
12- {-# LANGUAGE TypeFamilies #-}
1312{-# LANGUAGE TypeApplications #-}
14- {-# LANGUAGE MultiParamTypeClasses #-}
13+ {-# LANGUAGE TypeFamilies #-}
1514
1615module Main where
1716
17+ import Data.Function
1818import Data.Int
1919import qualified Data.List.NonEmpty as NonEmpty
2020import Data.Text (Text )
2121import Data.Time
2222import Database.Beam
2323import Database.Beam.DuckDB
2424import Database.DuckDB.Simple
25- import Data.Function
2625
2726data ExamT f = Exam
2827 { _examId :: Columnar f Int32 ,
2928 _examName :: Columnar f Text ,
3029 _examScore :: Columnar f Double ,
3130 _examDate :: Columnar f Day
32- } deriving (Generic , Beamable )
31+ }
32+ deriving (Generic , Beamable )
3333
3434type Exam = ExamT Identity
3535
3636deriving instance Show (ExamT Identity )
37+
3738deriving instance Eq (ExamT Identity )
3839
3940instance Table ExamT where
@@ -42,7 +43,7 @@ instance Table ExamT where
4243 primaryKey = ExamKey <$> _examId
4344
4445data ScoresDB f = ScoresDB
45- { _scores :: f (DataSourceEntity ExamT ) }
46+ { _scores :: f (DataSourceEntity ExamT )}
4647 deriving (Generic )
4748
4849deriving instance Database DuckDB ScoresDB
@@ -63,11 +64,12 @@ scoresDb =
6364 }
6465
6566main = do
66- Just maxScore <- withConnection " :memory:"
67- $ \ conn -> runBeamDuckDB conn
68- $ runSelectReturningOne
69- $ select
70- $ aggregate_
67+ Just maxScore <- withConnection " :memory:" $
68+ \ conn ->
69+ runBeamDuckDB conn $
70+ runSelectReturningOne $
71+ select $
72+ aggregate_
7173 (max_ . _examScore)
7274 (allFromDataSource_ (_scores scoresDb))
7375
0 commit comments