Merge rootR and todayR
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# OPTIONS_GHC -Wno-deriving-defaults #-}
|
||||
|
||||
module Yore.DB
|
||||
( DayIndex (..)
|
||||
@@ -10,6 +11,7 @@ module Yore.DB
|
||||
, readDayIndex
|
||||
, readDayPaths
|
||||
, getDayFileByIssue
|
||||
, getNumberOfIssues
|
||||
, Table (..)
|
||||
, getTables
|
||||
) where
|
||||
@@ -41,6 +43,10 @@ data DayFile = DayFile
|
||||
, relative_path :: FilePath
|
||||
} deriving (Show, Generic, Opium.FromRow)
|
||||
|
||||
newtype CountResult = CountResult
|
||||
{ count :: Int
|
||||
} deriving (Show, Generic, Opium.FromRow)
|
||||
|
||||
createDayIndex :: Day -> Opium.Connection -> IO (Either Opium.Error DayIndex)
|
||||
createDayIndex date = ex runIdentity .
|
||||
Opium.fetch
|
||||
@@ -70,5 +76,11 @@ getDayFileByIssue date issue = ex runIdentity .
|
||||
"SELECT yore.day_file.* FROM yore.day_index LEFT JOIN yore.day_file USING (day_index_id) WHERE day = $1 ORDER BY day_file_id LIMIT 1 OFFSET $2"
|
||||
(date, issue)
|
||||
|
||||
getNumberOfIssues :: Day -> Opium.Connection -> IO (Either Opium.Error Int)
|
||||
getNumberOfIssues date = ex (count . runIdentity) .
|
||||
Opium.fetch
|
||||
"SELECT count(*) FROM yore.day_index LEFT JOIN yore.day_file USING (day_index_id) WHERE day = $1"
|
||||
(Identity date)
|
||||
|
||||
ex :: (a -> b) -> IO (Either e a) -> IO (Either e b)
|
||||
ex = fmap . fmap
|
||||
|
||||
Reference in New Issue
Block a user