diff options
author | Julien Dessaux | 2023-07-02 22:58:30 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-02 23:01:01 +0200 |
commit | a775330b4fa17fb367e55343e6fda6c7ae9e34b4 (patch) | |
tree | 8c572f799dbf434459d4659e32559c121421f120 /haskell/src/SpaceTraders/Database | |
parent | Moved the nodejs agent to its own subfolder to make room for my haskell agent (diff) | |
download | spacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.tar.gz spacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.tar.bz2 spacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.zip |
Bootstrapped my haskell client
Diffstat (limited to 'haskell/src/SpaceTraders/Database')
-rw-r--r-- | haskell/src/SpaceTraders/Database/Agents.hs | 14 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Database/Tokens.hs | 18 |
2 files changed, 32 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/Database/Agents.hs b/haskell/src/SpaceTraders/Database/Agents.hs new file mode 100644 index 0000000..5be7389 --- /dev/null +++ b/haskell/src/SpaceTraders/Database/Agents.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module SpaceTraders.Database.Agents + ( setAgent + ) where + +import Data.Aeson +import qualified Database.SQLite.Simple as S + +import SpaceTraders.Model.Agent + +setAgent :: S.Connection -> Agent -> IO () +setAgent conn agent = S.execute conn "INSERT INTO agents(data) VALUES (json(?));" (S.Only (encode agent)) diff --git a/haskell/src/SpaceTraders/Database/Tokens.hs b/haskell/src/SpaceTraders/Database/Tokens.hs new file mode 100644 index 0000000..b907609 --- /dev/null +++ b/haskell/src/SpaceTraders/Database/Tokens.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module SpaceTraders.Database.Tokens + ( getToken + , setToken + ) where + +import qualified Database.SQLite.Simple as S +import qualified Data.Text as T + +getToken :: S.Connection -> IO (T.Text) +getToken conn = do + [[token]] <- S.query_ conn "SELECT data FROM tokens;" + return token + +setToken :: S.Connection -> T.Text -> IO () +setToken conn value = S.execute conn "INSERT INTO tokens(data) VALUES (?);" (S.Only value) |