• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Courseography / courseography / bd4175d1-f249-4c7e-b1a7-608a150c31cb

13 Jun 2025 05:02PM UTC coverage: 32.165%. Remained the same
bd4175d1-f249-4c7e-b1a7-608a150c31cb

push

circleci

web-flow
Refactored Graph functions into new Models.Graph module (#1566)

21 of 140 branches covered (15.0%)

Branch coverage included in aggregate %.

0 of 50 new or added lines in 2 files covered. (0.0%)

5 existing lines in 1 file now uncovered.

640 of 1915 relevant lines covered (33.42%)

26.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Database/CourseInsertion.hs
1
{-|
2
    Module      : Database.CourseInsertion
3
    Description : Functions that insert/update course information in the
4
                  database.
5

6
This module contains a bunch of functions related to inserting information
7
into the database. These functions are used as helpers for the WebParsing module.
8
-}
9

10
module Database.CourseInsertion
11
    (insertCourse) where
12

13
import qualified Data.Text as T
14
import Database.Persist.Class (selectKeysList)
15
import Database.Persist.Sqlite (SqlPersistM, insert_, selectFirst, (==.))
16
import Database.Tables hiding (breadth, distribution)
17

18
--contains' :: PersistEntity m => T.Text -> SqlPersistM m
19
--contains field query = Filter field (Left $ T.concat ["%", query, "%"]) (BackendSpecificFilter "LIKE")
20

21
-- Get Key of correspondig record in Distribution column
22
getDistributionKey :: T.Text -> SqlPersistM (Maybe (Key Distribution))
UNCOV
23
getDistributionKey description_ = do
×
24
    keyListDistribution :: [Key Distribution] <- selectKeysList [ DistributionDescription ==. description_ ] []
×
25
    -- option: keyListDistribution :: [DistributionId] <- selectKeysList [ DistributionDescription `contains'` description] []
UNCOV
26
    return $ case keyListDistribution of
×
27
        [] -> Nothing
×
28
        _ -> Just (head keyListDistribution)
×
29

30
getBreadthKey :: T.Text -> SqlPersistM (Maybe (Key Breadth))
UNCOV
31
getBreadthKey description_ = do
×
32
    keyListBreadth :: [Key Breadth] <- selectKeysList [ BreadthDescription ==. description_ ] []
×
33
    -- option: selectKeysList [ BreadthDescription `contains'` description] []
UNCOV
34
    return $ case keyListBreadth of
×
35
        [] -> Nothing
×
36
        _ -> Just (head keyListBreadth)
×
37

38
-- | Inserts course into the Courses table.
39
insertCourse :: (Courses, T.Text, T.Text) -> SqlPersistM ()
UNCOV
40
insertCourse (course, breadth, distribution) = do
×
41
    maybeCourse <- selectFirst [CoursesCode ==. coursesCode course] []
×
42
    breadthKey <- getBreadthKey breadth
×
43
    distributionKey <- getDistributionKey distribution
×
44
    case maybeCourse of
×
45
        Nothing -> insert_ $ course {coursesBreadth = breadthKey,
×
46
                                     coursesDistribution = distributionKey}
×
47
        Just _ -> return ()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc