Skip to content

Commit

Permalink
[#45] Add function for inserting issues into DB
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
rashadg1030 committed Jun 18, 2019
1 parent 41f7748 commit 3b481ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/IW/Core/Issue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ data Issue = Issue
, issueUrl :: Text
, issueRepoId :: Int
} deriving stock (Generic, Show, Eq)
deriving anyclass (FromRow)
deriving anyclass (FromRow, ToRow)
deriving (FromJSON, ToJSON)
16 changes: 15 additions & 1 deletion src/IW/Db/Issue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module IW.Db.Issue

import IW.App (WithError)
import IW.Core.Issue (Issue)
import IW.Db.Functions (WithDb, asSingleRow, query, queryRaw)
import IW.Db.Functions (WithDb, asSingleRow, executeMany, query, queryRaw)

-----------
-- QUERY --
-----------

getIssues :: (WithDb env m, WithError m) => m [Issue]
getIssues = queryRaw [sql|
Expand All @@ -33,3 +37,13 @@ getIssuesByLabel label = query [sql|
JOIN labels ON labels.id = issues_labels.label_id
WHERE labels.label_name = ?
|] (Only label)

------------
-- INSERT --
------------

insertIssues :: (WithDb env m, WithError m) => [Issue] -> m ()
insertIssues = executeMany [sql|
INSERT INTO issues (issue_number, issue_title, issue_body, issue_url, repo_id)
VALUES (?,?,?,?,?)
|]

0 comments on commit 3b481ba

Please sign in to comment.