node.js - 在 Etherpad Lite 中迁移大型 SQLite 数据库的最佳方法

标签 node.js sqlite etherpad

我使用 sqlite 运行 Etherpad Lite 已有两年了。现在我将把数据库迁移到MySQL或者Redis。我使用 bin/migrateDirtyDBtoMySQL.js 作为灵感编写了我自己的小迁移脚本。这是:

require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) {

    process.chdir(npm.root+'/..');

    var settings = require("ep_etherpad-lite/node/utils/Settings");
    var sqlite3 = require('sqlite3');
    var sqliteDb = new sqlite3.Database('var/sqlite.db');
    var db = require("ep_etherpad-lite/node/db/DB");

    db.init(function() {
        db = db.db;

        sqliteDb.each("SELECT * FROM store", function(err, row) {
            db.set(row.key,row.value);
        });
    });

}); 

安装 sqlite3 依赖项后,它可以工作但是我的 sqlite.db 文件超过 700 MB 并且调用:

node migrateSqliteDBtoEtherpad.js

以终止信号终止。我如何使用nodejs和etherpad-lite处理如此庞大的数据库?

最佳答案

一种使用 PHP 将数据迁移到 Redis 的解决方案:

<?php

require __DIR__ . '/vendor/autoload.php';

$db = new PDO('sqlite:sqlite.db');
$redis = new Predis\Client();

foreach ($db->query("SELECT * FROM store") as $row) {
    $redis->set($row['key'], $row['value']);
}

在此示例中,您必须通过 Composer 安装 Predis。

关于node.js - 在 Etherpad Lite 中迁移大型 SQLite 数据库的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18694659/

相关文章:

node.js - 如何在 Node.js 中 'accumulate' 原始流?

mysql - 如何使用 Promise 在 Node 中进行多个 mysql 查询

r - 使用 dplyr 过滤 SQLite 数据库时,是否应该避免 `|`?

ruby-on-rails - 我想使用 EtherPad(或克隆)。我的网站正在运行 Ruby on Rails。 API 还是本地安装?

php - 在线 "diary"- 现有脚本/mysql/fwrite()?

javascript - 如何在 Javascript 中格式化 HTTP API 调用?

node.js - 在 VS Code 中调试 Typescript Apollo Server (graphQL) 时未绑定(bind)断点

node.js - 使用 fs.write 而不是 fs.writeFile 覆盖文件的所有内容

node.js - Discord Bot 数据库 (JAVASCRIPT)

sql - 如果 SQLite 中存在则删除列?