Skip to content

Commit

Permalink
[#45] Add function for converting an issue to a 5-tuple for DB insertion
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
rashadg1030 committed Jun 25, 2019
1 parent c9bbea2 commit 8fa601c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/IW/Db/Issue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ module IW.Db.Issue
( getIssues
, getIssueById
, getIssuesByLabel
, issueToRow
, insertIssue
, insertIssues
) where

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

Expand Down Expand Up @@ -41,12 +43,15 @@ getIssuesByLabel label = query [sql|
WHERE labels.name = ?
|] (Only label)

issueToRow :: Issue -> (Int, Text, Text, Text, Id Repo)
issueToRow Issue{..} = (issueNumber, issueTitle, issueBody, issueUrl, issueRepoId)

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

-- | Insert a list of issues into the database
insertIssues :: (WithDb env m) => [Issue] -> m ()
Expand Down
1 change: 1 addition & 0 deletions src/TestDb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IW.App.Env (Env (..))
import IW.Core.Issue (Issue (..))
import IW.Core.Id (Id (..))
import IW.Config (Config (..))
import IW.Db.Issue (issueToRow)
import Toml (TomlCodec, (.=))
import qualified Toml
import qualified Database.PostgreSQL.Simple as Sql
Expand Down

0 comments on commit 8fa601c

Please sign in to comment.