mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-27 10:45:54 +00:00
e05a35e26e
* postgres: modules structure (#5401) * postgres: schema, field conversions (#5430) * postgres: rework chat list pagination query (#5441) * prepare cabal for merge * restore cabal changes * simplexmq * postgres: implementation wip (tests don't pass) (#5481) * restore ios file * postgres: implementation - tests pass (#5487) * refactor DB options * refactor * line * style * style * refactor * $ * update simplexmq * constraintError * handleDBErrors * fix * remove param * Ok * case * case * case * comment --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
28 lines
1.2 KiB
Haskell
28 lines
1.2 KiB
Haskell
{-# LANGUAGE CPP #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Simplex.Chat.Store.AppSettings where
|
|
|
|
import Control.Monad (join)
|
|
import Control.Monad.IO.Class (liftIO)
|
|
import qualified Data.Aeson as J
|
|
import Data.Maybe (fromMaybe)
|
|
import Simplex.Chat.AppSettings (AppSettings (..), combineAppSettings, defaultAppSettings, defaultParseAppSettings)
|
|
import Simplex.Messaging.Agent.Store.AgentStore (maybeFirstRow)
|
|
import qualified Simplex.Messaging.Agent.Store.DB as DB
|
|
#if defined(dbPostgres)
|
|
import Database.PostgreSQL.Simple (Only (..))
|
|
#else
|
|
import Database.SQLite.Simple (Only (..))
|
|
#endif
|
|
|
|
saveAppSettings :: DB.Connection -> AppSettings -> IO ()
|
|
saveAppSettings db appSettings = do
|
|
DB.execute_ db "DELETE FROM app_settings"
|
|
DB.execute db "INSERT INTO app_settings (app_settings) VALUES (?)" (Only $ J.encode appSettings)
|
|
|
|
getAppSettings :: DB.Connection -> Maybe AppSettings -> IO AppSettings
|
|
getAppSettings db platformDefaults = do
|
|
stored_ <- join <$> liftIO (maybeFirstRow (J.decodeStrict . fromOnly) $ DB.query_ db "SELECT app_settings FROM app_settings")
|
|
pure $ combineAppSettings (fromMaybe defaultAppSettings platformDefaults) (fromMaybe defaultParseAppSettings stored_)
|