mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-12 06:34:59 +00:00
core: support postgres backend (#5403)
* 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>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Simplex.Chat.Store
|
||||
( DBStore,
|
||||
StoreError (..),
|
||||
@@ -7,20 +9,43 @@ module Simplex.Chat.Store
|
||||
AutoAccept (..),
|
||||
createChatStore,
|
||||
migrations, -- used in tests
|
||||
#if defined(dbPostgres)
|
||||
chatSchema,
|
||||
agentSchema,
|
||||
#else
|
||||
chatStoreFile,
|
||||
agentStoreFile,
|
||||
#endif
|
||||
withTransaction,
|
||||
)
|
||||
where
|
||||
|
||||
import Data.ByteArray (ScrubbedBytes)
|
||||
import Simplex.Chat.Store.Migrations
|
||||
import Simplex.Chat.Store.Profiles
|
||||
import Simplex.Chat.Store.Shared
|
||||
import Simplex.Messaging.Agent.Store.SQLite (createDBStore)
|
||||
import Simplex.Messaging.Agent.Store.SQLite.Common (DBStore (..), withTransaction)
|
||||
import Simplex.Messaging.Agent.Store.Common (DBStore (..), withTransaction)
|
||||
import Simplex.Messaging.Agent.Store.Shared (MigrationConfirmation, MigrationError)
|
||||
#if defined(dbPostgres)
|
||||
import Database.PostgreSQL.Simple (ConnectInfo (..))
|
||||
import Simplex.Chat.Store.Postgres.Migrations
|
||||
import Simplex.Messaging.Agent.Store.Postgres (createDBStore)
|
||||
#else
|
||||
import Data.ByteArray (ScrubbedBytes)
|
||||
import Simplex.Chat.Store.SQLite.Migrations
|
||||
import Simplex.Messaging.Agent.Store.SQLite (createDBStore)
|
||||
#endif
|
||||
|
||||
#if defined(dbPostgres)
|
||||
createChatStore :: ConnectInfo -> String -> MigrationConfirmation -> IO (Either MigrationError DBStore)
|
||||
createChatStore connectInfo schema = createDBStore connectInfo schema migrations
|
||||
|
||||
chatSchema :: String -> String
|
||||
chatSchema "" = "chat_schema"
|
||||
chatSchema prefix = prefix <> "_chat_schema"
|
||||
|
||||
agentSchema :: String -> String
|
||||
agentSchema "" = "agent_schema"
|
||||
agentSchema prefix = prefix <> "_agent_schema"
|
||||
#else
|
||||
createChatStore :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> Bool -> IO (Either MigrationError DBStore)
|
||||
createChatStore dbPath key keepKey = createDBStore dbPath key keepKey migrations
|
||||
|
||||
@@ -29,3 +54,4 @@ chatStoreFile = (<> "_chat.db")
|
||||
|
||||
agentStoreFile :: FilePath -> FilePath
|
||||
agentStoreFile = (<> "_agent.db")
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user