1
こんにちは、私はNodeJSを比較的新しくしており、ORMとしてObjectionJSを使用しています。 各行の一部のフィールドを変更するために、自分のusersテーブルの移行スクリプトを実行します。NodeJSとObjectionJsを使用したページングクエリ
私はこの
export default class UserMigration {
constructor(firstId, lastId = 9000000) {
this.firstId = firstId;
this.lastId = lastId;
}
migrate() {
let more = true;
let page = 0;
let batchSize = 100;
while(more) {
UserModel.query().where('id', '>=', this.firstId)
.where('id', '<=', this.lastId)
.page(page, batchSize)
.then((result) => {
let users = result.results;
debug('Page: ', page);
debug('PageSize: ', users.length)
users.forEach((user) => {
// Do something here
});
if(result.results.length < batchSize) {
more = false
} else {
page++;
}
})
}
}
}
のようなものを作るしかし、その後、私はwhile
ブロックが同期的に実行されている間、クエリは非同期に実行されていることを認識し、それが正しいのですか?
一度にすべてのユーザーを返す大きなクエリを1つ作成しなくても、どのように移行できますか?
ありがとうございます!