blob: 07749be2376546d7c7046b7ffe40df3acddd5e7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
{-# LANGUAGE OverloadedStrings #-}
module SpaceTraders.Database.Systems
( addSystems
, getSystems
) where
import Control.Monad.Reader
import Data.Aeson
import qualified Database.SQLite.Simple as S
import SpaceTraders
import SpaceTraders.Model.System
import SpaceTraders.Utils
addSystems :: (HasDatabaseConn env, MonadIO m, MonadReader env m) => [System] -> m ()
addSystems systems = do
env <- ask
let conn = getConn env
liftIO $ S.withTransaction conn $ S.executeMany conn "INSERT INTO systems(data) VALUES (json(?));" $ S.Only <$> map encode systems
getSystems :: (HasDatabaseConn env, MonadIO m, MonadReader env m) => m [System]
getSystems = query_ "SELECT data FROM systems;"
|