{-| Create and populate a new database, replacing the old -}
buildDatabase :: FilePath -> String -> IO ()
buildDatabase dbDir dbName =
  do -- place tmp file in same dir as db to allow atomic move
     let tmpDb = dbDir </> dbName ++ "-partial"
     -- build database in temporary path
     conn <- connectSqlite3 tmpDb
     createTable conn
     populate conn =<< parseCabal
     -- commit and disconnect
     commit conn
     disconnect conn
     -- move new database over old one
     renameFile tmpDb $ dbDir </> dbName

{-| Query a database, using the output from Cabal -}
buildDatabase :: FilePath -> String -> IO ()
buildDatabase dbDir dbName =
  do -- place tmp file in same dir as db to allow atomic move
     let tmpDb = dbDir </> dbName ++ "-partial"
     -- build database in temporary path
     conn <- connectSqlite3 tmpDb
     createTable conn
     populate conn =<< parseCabal
     -- commit and disconnect
     commit conn
     disconnect conn
     -- move new database over old one
     renameFile tmpDb $ dbDir </> dbName

{-| Query a database, using the output from Cabal -}
buildDatabase dbDir dbName =
  do -- place tmp file in same dir as db to allow atomic move
     let tmpDb = dbDir </> dbName ++ "-partial"
     -- build database in temporary path
     conn <- connectSqlite3 tmpDb
     createTable conn
     populate conn =<< parseCabal
     -- commit and disconnect
     commit conn
     disconnect conn
     -- move new database over old one
     renameFile tmpDb $ dbDir </> dbName

{-| Query a database, using the output from Cabal -}