我想知道哪种是在数据库中更新或插入批量数据的最佳设计模式。
我的应用使用MVVM模式,其中模型执行“ CUD”操作 还有一个用于复杂“ R”查询的QueryObject模式。
例如,我有一些类似的代码:
const book = new BookModel(data);
const id = await book.save();
和其他类似的东西:
const bks = await new BooksQuery().orderByAuthor().whereGenre('engineering').execute();
const books = books.map((book) => new BooksViewModel(req, book));
this.render(req, res, 'books', books);
让我们假设我必须保存许多书籍的排序顺序。 问题是,从逻辑上讲它去了哪里?
const book = new BookModel();
const result = await book.saveSort(orderedIds);
或
const book = new BookModel(orderedIds);
const result = await book.saveSort();
const result = await new BooksCommand().saveSort(orderedIds).execute();
谢谢!