mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-26 09:44:55 +00:00
core: Mobile.hs postgres interface (#5545)
* core: Mobile.hs postgres interface * sqlite * fix * errors * postgres * rename * rename, refactor * merge files * rename * update simplexmq --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
{-# LANGUAGE ApplicativeDo #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Simplex.Chat.Options.SQLite where
|
||||
|
||||
import Data.ByteArray (ScrubbedBytes)
|
||||
import qualified Data.ByteArray as BA
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Foreign.C.String
|
||||
import Options.Applicative
|
||||
import Simplex.Messaging.Agent.Store.Interface (DBOpts (..))
|
||||
import System.FilePath (combine)
|
||||
|
||||
data ChatDbOpts = ChatDbOpts
|
||||
@@ -42,3 +47,42 @@ chatDbOptsP appDir defaultDbName = do
|
||||
|
||||
dbString :: ChatDbOpts -> String
|
||||
dbString ChatDbOpts {dbFilePrefix} = dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
|
||||
|
||||
toDBOpts :: ChatDbOpts -> String -> Bool -> DBOpts
|
||||
toDBOpts ChatDbOpts {dbFilePrefix, dbKey, vacuumOnMigration} dbSuffix keepKey = do
|
||||
DBOpts
|
||||
{ dbFilePath = dbFilePrefix <> dbSuffix,
|
||||
dbKey,
|
||||
keepKey,
|
||||
vacuum = vacuumOnMigration
|
||||
}
|
||||
|
||||
chatSuffix :: String
|
||||
chatSuffix = "_chat.db"
|
||||
|
||||
agentSuffix :: String
|
||||
agentSuffix = "_agent.db"
|
||||
|
||||
mobileDbOpts :: CString -> CString -> IO ChatDbOpts
|
||||
mobileDbOpts fp key = do
|
||||
dbFilePrefix <- peekCString fp
|
||||
dbKey <- BA.convert <$> B.packCString key
|
||||
pure $
|
||||
ChatDbOpts
|
||||
{ dbFilePrefix,
|
||||
dbKey,
|
||||
vacuumOnMigration = True
|
||||
}
|
||||
|
||||
-- used to create new chat controller,
|
||||
-- at that point database is already opened, and the key in options is not used
|
||||
removeDbKey :: ChatDbOpts -> ChatDbOpts
|
||||
removeDbKey ChatDbOpts {dbFilePrefix, vacuumOnMigration} =
|
||||
ChatDbOpts
|
||||
{ dbFilePrefix,
|
||||
dbKey = "",
|
||||
vacuumOnMigration
|
||||
}
|
||||
|
||||
errorDbStr :: DBOpts -> String
|
||||
errorDbStr DBOpts {dbFilePath} = dbFilePath
|
||||
|
||||
Reference in New Issue
Block a user