Skip to content

Commit

Permalink
[#45] Add function for inserting issue into DB
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
rashadg1030 committed Jun 23, 2019
1 parent cfeb845 commit 76bc370
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion issue-wanted.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ library

-- Sync Worker
IW.Sync
IW.Sync.Insert
IW.Sync.Search

build-depends: aeson >= 1.4
, bytestring ^>= 0.10
, case-insensitive ^>= 1.2
Expand Down
16 changes: 15 additions & 1 deletion src/IW/Db/Issue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ module IW.Db.Issue
import IW.App (WithError)
import IW.Core.Issue (Issue (..))
import IW.Core.Id (Id (..))
import IW.Db.Functions (WithDb, asSingleRow, query, queryRaw)
import IW.Db.Functions (WithDb, asSingleRow, execute, query, queryRaw)


-- | Get a list of all issues from database
getIssues :: (WithDb env m) => m [Issue]
getIssues = queryRaw [sql|
SELECT id, number, title, body, url, repo_id
FROM issues
|]

-- | Get a single issue with the associated id
getIssueById :: (WithDb env m, WithError m) => Id Issue -> m Issue
getIssueById issueId = asSingleRow $ query [sql|
SELECT id, number, title, body, url, repo_id
FROM issues
WHERE id = ?
|] (Only issueId)

-- | Get a list of issues filtered by label name
getIssuesByLabel :: (WithDb env m) => Text -> m [Issue]
getIssuesByLabel label = query [sql|
SELECT issues.id, issues.number, issues.title, issues.body, issues.url, issues.repo_id
Expand All @@ -35,3 +38,14 @@ getIssuesByLabel label = query [sql|
JOIN labels ON labels.id = issues_labels.label_id
WHERE labels.name = ?
|] (Only label)

-- | Insert a single issue into the database
insertIssue :: (WithDb env m) => Issue -> m ()
insertIssue Issue{..} = execute [sql|
INSERT INTO issues (number, title, body, url, repo_id)
VALUES (?, ?, ?, ?, ?);
|] (issueNumber, issueTitle, issueBody, issueUrl, issueRepoId)

-- | Insert a list of issues into the database
insertIssues :: (WithDb env m) => [Issue] -> m ()
insertIssues = undefined
2 changes: 2 additions & 0 deletions src/IW/Sync/Insert.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module IW.Sync.Insert where

0 comments on commit 76bc370

Please sign in to comment.