mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-30 18:35:59 +00:00
agent: creating schema
This commit is contained in:
@@ -22,6 +22,7 @@ dependencies:
|
||||
- network == 3.1.*
|
||||
- sqlite-simple == 0.4.*
|
||||
- stm
|
||||
- text == 1.2.*
|
||||
- time == 1.9.*
|
||||
- unliftio == 0.2.*
|
||||
- unliftio-core == 0.1.*
|
||||
|
||||
BIN
smp-agent.db
Normal file
BIN
smp-agent.db
Normal file
Binary file not shown.
@@ -9,9 +9,11 @@ import Control.Monad.IO.Unlift
|
||||
import Crypto.Random
|
||||
import Data.Map.Strict (Map)
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified Database.SQLite.Simple as DB
|
||||
import Network.Socket (HostName, ServiceName)
|
||||
import Numeric.Natural
|
||||
import Simplex.Messaging.Agent.Command
|
||||
import Simplex.Messaging.Agent.Store.SQLite.Schema
|
||||
import qualified Simplex.Messaging.Server.Transmission as SMP
|
||||
import UnliftIO.STM
|
||||
|
||||
@@ -24,7 +26,8 @@ data AgentConfig = AgentConfig
|
||||
|
||||
data Env = Env
|
||||
{ config :: AgentConfig,
|
||||
idsDrg :: TVar ChaChaDRG
|
||||
idsDrg :: TVar ChaChaDRG,
|
||||
db :: DB.Connection
|
||||
}
|
||||
|
||||
data AgentClient = AgentClient
|
||||
@@ -51,7 +54,14 @@ newServerClient qSize = do
|
||||
sndQ <- newTBQueue qSize
|
||||
return ServerClient {sndQ, commands = M.empty}
|
||||
|
||||
openDB :: MonadUnliftIO m => AgentConfig -> m DB.Connection
|
||||
openDB AgentConfig {dbFile} = liftIO $ do
|
||||
db <- DB.open dbFile
|
||||
createSchema db
|
||||
return db
|
||||
|
||||
newEnv :: (MonadUnliftIO m, MonadRandom m) => AgentConfig -> m Env
|
||||
newEnv config = do
|
||||
idsDrg <- drgNew >>= newTVarIO
|
||||
return Env {config, idsDrg}
|
||||
db <- openDB config
|
||||
return Env {config, idsDrg, db}
|
||||
|
||||
@@ -3,13 +3,18 @@
|
||||
module Simplex.Messaging.Agent.Store.SQLite.Schema where
|
||||
|
||||
import Control.Monad.IO.Unlift
|
||||
import qualified Data.Text as T
|
||||
import Database.SQLite.Simple
|
||||
|
||||
createSchema :: MonadUnliftIO m => Connection -> m ()
|
||||
createSchema conn = do
|
||||
sql "recipient_queues"
|
||||
sql "sender_queues"
|
||||
sql "connections"
|
||||
sql "messages"
|
||||
-- sql "sender_queues"
|
||||
-- sql "connections"
|
||||
-- sql "messages"
|
||||
return ()
|
||||
where
|
||||
sql name = return ()
|
||||
sql name = liftIO $ do
|
||||
q <- readFile $ "./src/Simplex/Messaging/Agent/Store/SQLite/sql/" <> name <> ".sql"
|
||||
putStrLn q
|
||||
execute_ conn . Query . T.pack $ q
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE IF NOT EXISTS recipient_queues
|
||||
( id INTEGER PRIMARY KEY,
|
||||
rcvId TEXT
|
||||
)
|
||||
Reference in New Issue
Block a user