Insertion support

This commit is contained in:
2020-12-30 23:29:56 +02:00
parent 98341a8c9f
commit 4806e06444
10 changed files with 202 additions and 9 deletions

54
src/Data/Buuka.hs Normal file
View File

@ -0,0 +1,54 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Buuka
( BuukaQ(..)
, BuukaU(..)
, BuukaEntry(..)
, URL(..)
, insert
)
where
import Data.Map
(Map)
import qualified Data.Map.Strict as M
import Database.Migrations
import Data.Aeson
import GHC.Generics
(Generic)
import Control.Monad.Reader
import Control.Monad.State
newtype URL = URL String
deriving stock (Show, Eq, Generic, Ord)
deriving newtype (ToJSON, FromJSON, FromJSONKey, ToJSONKey)
data BuukaEntry
= BuukaEntry { url :: URL
, title :: Maybe String
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
instance SafeJSON BuukaEntry where
type Version BuukaEntry = 0
newtype Buuka = Buuka ( Map URL BuukaEntry )
deriving newtype (Semigroup, Monoid, FromJSON, ToJSON)
insert :: BuukaEntry -> Buuka -> Buuka
insert e (Buuka b) = Buuka (M.insert (url e) e b)
instance SafeJSON Buuka where
type Version Buuka = 0
newtype BuukaQ a = BuukaQ { runBuukaQ :: Reader Buuka a }
deriving newtype (Functor, Applicative, Monad, MonadReader Buuka)
-- Last write wins
newtype BuukaU a = BuukaU { runBuukaU :: State Buuka a }
deriving newtype (Functor, Applicative, Monad, MonadState Buuka)

4
src/Data/Environment.hs Normal file
View File

@ -0,0 +1,4 @@
module Data.Environment where
newtype Environment = Environment { workdir :: FilePath }
deriving stock (Show, Eq)