[haskell] Implemented pagination and systems list api call
This commit is contained in:
parent
8249bf432a
commit
7bd1c116c2
9 changed files with 186 additions and 8 deletions
23
haskell/src/SpaceTraders/Database/Systems.hs
Normal file
23
haskell/src/SpaceTraders/Database/Systems.hs
Normal file
|
@ -0,0 +1,23 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module SpaceTraders.Database.Systems
|
||||
( addSystems
|
||||
, getSystems
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Maybe
|
||||
import qualified Database.SQLite.Simple as S
|
||||
|
||||
import Data.Text.Encoding (encodeUtf8Builder)
|
||||
import Data.ByteString.Builder(toLazyByteString)
|
||||
|
||||
import SpaceTraders.Model.System
|
||||
|
||||
addSystems :: S.Connection -> [System] -> IO ()
|
||||
addSystems conn systems = S.withTransaction conn $ S.executeMany conn "INSERT INTO systems(data) VALUES (json(?));" $ S.Only <$> map encode systems
|
||||
|
||||
getSystems :: S.Connection -> IO [System]
|
||||
getSystems conn = do
|
||||
ret <- S.query_ conn "SELECT data from systems;"
|
||||
return . catMaybes $ map (decode . toLazyByteString . encodeUtf8Builder . head) ret
|
Loading…
Add table
Add a link
Reference in a new issue