This commit is contained in:
Ryan Mulligan 2021-12-05 08:11:02 -08:00
parent c78b63b443
commit 90352bd289

34
src/Package.hs Normal file
View File

@ -0,0 +1,34 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Package where
import OurPrelude
import qualified Database.SQLite.Simple as SQL
import qualified Utils
data Package = Package
{ attrPath :: Text
, targetVersion :: Utils.Version
, tried :: Bool
}
deriving (Show, Eq, Ord)
instance SQL.FromRow Package where
fromRow = do
attrPath <- SQL.field
targetVersion <- SQL.field
tried <- SQL.field
pure Package {..}
getDBPath :: IO FilePath
getDBPath = do
cacheDir <- Utils.cacheDir
pure $ cacheDir </> "package.sqlite3"
withDB :: (SQL.Connection -> IO a) -> IO a
withDB action = do
dbPath <- getDBPath
SQL.withConnection dbPath action