Skip to main content

クエリエンジンAPIを使用した一括操作

Caution

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.

Caution

パフォーマンスの問題を避けるため、リレーションに対する一括操作は許可されていません。

createMany()

複数のエントリを作成します。

構文: createMany(parameters) => { count: number, ids: id[] }

パラメータ

パラメータタイプ説明
dataオブジェクトの配列入力データの配列
Caution
  • 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 }

パラメータ

パラメータタイプ説明
whereWhereParameter使用するフィルタ
dataオブジェクト入力データ

await AI Marketer.db.query("api::shop.article").updateMany({
where: {
price: 20,
},
data: {
price: 18,
},
});

// { count: 42 }

deleteMany()

パラメータに一致する複数のエントリを削除します。

構文: deleteMany(parameters) => { count: number }

パラメータ

パラメータタイプ説明
whereWhereParameter使用するフィルタ

await AI Marketer.db.query("api::blog.article").deleteMany({
where: {
title: {
$startsWith: "v3",
},
},
});

// { count: 42 }

集計

count()

パラメータに一致するエントリを数えます。

構文: count(parameters) => number

パラメータ

パラメータタイプ説明
whereWhereParameter使用するフィルタ
const count = await AI Marketer.db.query("api::blog.article").count({
where: {
title: {
$startsWith: "v3",
},
},
});

// 12