evict note folders from createUserRecord

This commit is contained in:
IC Rainbow
2024-01-03 22:21:05 +02:00
parent 211a440e78
commit cf408778d4
6 changed files with 18 additions and 8 deletions
+7 -1
View File
@@ -5,15 +5,21 @@
module Simplex.Chat.Store.NoteFolders where
import Control.Monad.Except (ExceptT (..))
import Control.Monad.IO.Class (liftIO)
import Data.Time (getCurrentTime)
import Database.SQLite.Simple (Only (..))
import Database.SQLite.Simple.QQ (sql)
import Simplex.Chat.Store.Shared (StoreError (..))
import Simplex.Chat.Store.Shared (StoreError (..), checkConstraint)
import Simplex.Chat.Types (NoteFolder (..), NoteFolderId, NoteFolderName, User (..))
import Simplex.Messaging.Agent.Protocol (UserId)
import Simplex.Messaging.Agent.Store.SQLite (firstRow)
import qualified Simplex.Messaging.Agent.Store.SQLite.DB as DB
createNoteFolder :: DB.Connection -> User -> ExceptT StoreError IO ()
createNoteFolder db User {userId} =
checkConstraint SENoteFolderAlreadyCreated . liftIO $
DB.execute db [sql| INSERT INTO note_folders (user_id) VALUES (?) |] (Only userId)
getNoteFolderIdByName :: DB.Connection -> User -> NoteFolderName -> ExceptT StoreError IO NoteFolderId
getNoteFolderIdByName db User {userId} ldn =
ExceptT . firstRow fromOnly (SENoteFolderNotFoundByName ldn) $