Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Haskell Persistent在数据库之间复制数据_Haskell_Conduit_Haskell Persistent - Fatal编程技术网

使用Haskell Persistent在数据库之间复制数据

使用Haskell Persistent在数据库之间复制数据,haskell,conduit,haskell-persistent,Haskell,Conduit,Haskell Persistent,首先,我有一个大型Sqlite数据库。我想使用Haskell持久库以流式方式将此数据库中的数据子集复制到另一个Sqlite数据库 这是我唯一能做到的,但是与在内存中加载数据然后将其写入新数据库相比,它非常慢(并且使用了更多内存) import Database.Persist.Sqlite (SqliteConf(..), runSqlite, runMigration, runSqlPersistMPool) import Database.Persist (entityVal, Entity

首先,我有一个大型Sqlite数据库。我想使用Haskell持久库以流式方式将此数据库中的数据子集复制到另一个Sqlite数据库

这是我唯一能做到的,但是与在内存中加载数据然后将其写入新数据库相比,它非常慢(并且使用了更多内存)

import Database.Persist.Sqlite (SqliteConf(..), runSqlite, runMigration, runSqlPersistMPool)
import Database.Persist (entityVal, Entity, createPoolConfig)
import Data.Pool (Pool)
import Data.Conduit (ConduitT, (.|), runConduit)
import qualified Data.Conduit.List as CL

main :: RIO App ()
main = do
  ipool <- liftIO $ createPoolConfig (SqliteConf "mydb.db" 1)
  opool <- liftIO $ createPoolConfig (SqliteConf "mydbsmall.db" 1)

  liftIO $ flip runSqlPersistMPool opool $ do
    runMigration migrateAll

  liftIO $ flip runSqlPersistMPool ipool $ do
    runConduit $ selectSource (distinct $ from $ \pays -> return pays) .| (migrate opool)

migrate :: (Monad m, MonadIO m)
        => Pool SqlBackend
        -> ConduitT (Entity Pays) Void m ()
migrate pool = CL.mapM_ (\e -> liftIO $ flip runSqlPersistMPool pool $ insertKey (entityKey e) (entityVal e))
导入Database.Persist.Sqlite(SqliteConf(..),runSqlite,runMigration,runSqlPersistMPool) 导入数据库.Persist(entityVal、Entity、createPoolConfig) 导入数据。池(池) 导入数据。导管(导管,(.|),管路导管) 导入符合条件的数据.conductor.List作为CL main::里约应用程序() main=do ipool池SqlBackend ->条件(实体支付)无效m() migrate pool=CL.mapM(\e->liftIO$flip runSqlPersistMPool$insertKey(entityKey e)(entityVal e)) 问题出在
migrate
函数中,因为我正在对导管流中的每个数据调用
runSqlPersistMPool

正确的方法是什么