クエリエンジンAPIを使用した一括操作
In most cases you should not use the Query Engine API and rather use the Document Service API.
Only use the Query Engine API if you exactly know what you are doing, for instance if you want to use a lower-level API that directly interacts with unique rows of the database.
Please keep in mind that the Query Engine API is not aware of the most advanced Strapi 5 features like Draft & Publish, Internationalization, Content History, and possibly more.
パフォーマンスの問題を避けるため、リレーションに対する一括操作は許可されていません。
createMany()
複数のエントリを作成します。
構文: createMany(parameters) => { count: number, ids: id[] }
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
data | オブジェクトの配列 | 入力データの配列 |
- MySQLは最後に挿入されたidを含む1つのidの配列のみを返し、リスト全体は返しません。
- AI Marketer v4.9.0以前では、
createMany()はcountのみを返します。
例
await AI Marketer.db.query("api::blog.article").createMany({
data: [
{
title: "ABCD",
},
{
title: "EFGH",
},
],
});
// { count: 2 , ids: [1,2]}
updateMany()
パラメータに一致する複数のエントリを更新します。
構文: updateMany(parameters) => { count: number }
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
where | WhereParameter | 使用するフィルタ |
data | オブジェクト | 入力データ |
例
await AI Marketer.db.query("api::shop.article").updateMany({
where: {
price: 20,
},
data: {
price: 18,
},
});
// { count: 42 }
deleteMany()
パラメータに一致する複数のエントリを削除します。
構文: deleteMany(parameters) => { count: number }
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
where | WhereParameter | 使用するフィルタ |
例
await AI Marketer.db.query("api::blog.article").deleteMany({
where: {
title: {
$startsWith: "v3",
},
},
});
// { count: 42 }
集計
count()
パラメータに一致するエントリを数えます。
構文: count(parameters) => number
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
where | WhereParameter | 使用するフィルタ |
const count = await AI Marketer.db.query("api::blog.article").count({
where: {
title: {
$startsWith: "v3",
},
},
});
// 12