summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Database
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/src/SpaceTraders/Database')
-rw-r--r--haskell/src/SpaceTraders/Database/Agents.hs14
-rw-r--r--haskell/src/SpaceTraders/Database/Tokens.hs18
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)