core: C API to migrate and check database (#1008)

* core: C API to migrate and check database

* update simplexmq
This commit is contained in:
Evgeny Poberezkin
2022-09-02 16:38:41 +01:00
committed by GitHub
parent 38b3965e68
commit 2b5e3a9459
10 changed files with 71 additions and 18 deletions
+7 -3
View File
@@ -20,8 +20,9 @@
module Simplex.Chat.Store
( SQLiteStore,
StoreError (..),
createStore,
createChatStore,
chatStoreFile,
agentStoreFile,
createUser,
getUsers,
setActiveUser,
@@ -276,12 +277,15 @@ migrations = sortBy (compare `on` name) $ map migration schemaMigrations
where
migration (name, query) = Migration {name = name, up = fromQuery query}
createStore :: FilePath -> String -> Bool -> IO SQLiteStore
createStore dbFilePath dbKey = createSQLiteStore dbFilePath dbKey migrations
createChatStore :: FilePath -> String -> Bool -> IO SQLiteStore
createChatStore dbFilePath dbKey = createSQLiteStore dbFilePath dbKey migrations
chatStoreFile :: FilePath -> FilePath
chatStoreFile = (<> "_chat.db")
agentStoreFile :: FilePath -> FilePath
agentStoreFile = (<> "_agent.db")
checkConstraint :: StoreError -> ExceptT StoreError IO a -> ExceptT StoreError IO a
checkConstraint err action = ExceptT $ runExceptT action `E.catch` (pure . Left . handleSQLError err)