-
Notifications
You must be signed in to change notification settings - Fork 38
/
Exercise.hs
63 lines (46 loc) · 2.1 KB
/
Exercise.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{-# LANGUAGE QuasiQuotes #-}
module Y2018.M01.D10.Exercise where
{--
Today's Haskell exercise is a bit of a warming-up exercise. Today we'll store
packet information in the packet table (the structure of the table matching
Packet (see Y2017.M12.D20.Exercise), and also write the fetch function that
retrieves packet information from the database from a given id (which we will
provide later).
We do this for auditing purposes. We wish to store not only the articles that
we store, but also information about what we stored and when. Storing packet
information is a piece of that puzzle.
... hm. Actually, I don't think a fetch function is necessary given how I'm
planning auditing. We shall see. For today, just write the toRow function
--}
import Data.Functor.Identity (Identity)
import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.SqlQQ
import Database.PostgreSQL.Simple.ToField (toField)
import Database.PostgreSQL.Simple.ToRow
-- below import available via 1HaskellADay git repository
import Data.LookupTable (LookupTable)
import Store.SQL.Util.Indexed
import Y2017.M12.D20.Exercise (Packet)
import Y2017.M12.D27.Exercise (DatedArticle)
import Y2017.M12.D29.Exercise (BlockParser)
import Y2018.M01.D04.Exercise hiding (etl) -- hint for bonus
insertPacketStmt :: Query
insertPacketStmt =
[sql|INSERT INTO packet (view,prev,next,total,count) VALUES (?,?,?,?,?)|]
insertPackets :: Connection -> [Packet] -> IO ()
insertPackets conn packs = undefined
instance ToRow Packet where
toRow pack = undefined
{--
Using Y2017.M12.D20.Exercise.readSample, load in the packet and store its
information.
--}
{-- BONUS -----------------------------------------------------------------
Rewrite the etl-process to store the packet information (that is: don't discard
packet information anymore) along with the articles. Remember to include logging
functionality as well!
--}
gruntWerk :: LookupTable -> BlockParser Identity Authors
-> (Connection -> [IxValue (DatedArticle Authors)] -> IO ())
-> Connection -> Packet -> IO (IxValue (DatedArticle Authors))
gruntWerk lk generator ancillaryFn conn pack = undefined