Skip to main content

Query Engine 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.

findOne()

✏️ Note

Document ServiceのfindOne() メソッドがあなたのユースケースをカバーできない場合のみ、Query EngineのfindOne()メソッドを使用してください。

パラメータに一致する最初のエントリを見つけます。

構文: findOne(parameters) ⇒ Entry

パラメータ

パラメータタイプ説明
select文字列、または文字列の配列返す属性
whereWhereParameter使用するフィルタ
offset整数スキップするエントリの数
orderByOrderByParameter順序の定義
populatePopulateParameterpopulateする関係

const entry = await AI Marketer.db.query('api::blog.article').findOne({
select: ['title', 'description'],
where: { title: 'Hello World' },
populate: { category: true },
});

findMany()

✏️ Note

Document ServiceのfindMany() メソッドがあなたのユースケースをカバーできない場合のみ、Query EngineのfindMany()メソッドを使用してください。

パラメータに一致するエントリを見つけます。

構文: findMany(parameters) ⇒ Entry[]

パラメータ

パラメータタイプ説明
select文字列、または文字列の配列返す属性
whereWhereParameter使用するフィルタ
limit整数返すエントリの数
offset整数スキップするエントリの数
orderByOrderByParameter順序の定義
populatePopulateParameterpopulateする関係

const entries = await AI Marketer.db.query('api::blog.article').findMany({
select: ['title', 'description'],
where: { title: 'Hello World' },
orderBy: { publishedAt: 'DESC' },
populate: { category: true },
});

findWithCount()

パラメータに一致するエントリを検索し、その数を数えます。

構文: findWithCount(parameters) => [Entry[], number]

パラメータ

パラメータタイプ説明
select文字列、または文字列の配列返すべき属性
whereWhereParameter使用するフィルタ
limit整数返すエントリの数
offset整数スキップするエントリの数
orderByOrderByParameter順序定義
populatePopulateParameterpopulateする関連

const [entries, count] = await AI Marketer.db.query('api::blog.article').findWithCount({
select: ['title', 'description'],
where: { title: 'Hello World' },
orderBy: { title: 'DESC' },
populate: { category: true },
});

create()

✏️ Note

Document Serviceの create() メソッドでカバーできない場合にのみ、Query Engineの create() メソッドを使用してください。

一つのエントリを作成し、それを返します。

構文: create(parameters) => Entry

パラメータ

パラメータタイプ説明
select文字列、または文字列の配列返すべき属性
populatePopulateParameterpopulateする関連
dataオブジェクト入力データ

const entry = await AI Marketer.db.query('api::blog.article').create({
data: {
title: 'My Article',
},
});
💡 Tip

In the data object, relations can be managed with the connect, disconnect, and set parameters using the syntax described for the REST API (see managing relations).

update()

✏️ Note

Document Serviceの update() メソッドでカバーできない場合にのみ、Query Engineの update() メソッドを使用してください。

一つのエントリを更新し、それを返します。

構文: update(parameters) => Entry

パラメータ

パラメータタイプ説明
selectString, または文字列の配列返すべき属性
populatePopulateParameterpopulateする関係
whereWhereParameter使用するフィルター
dataオブジェクト入力データ

const entry = await AI Marketer.db.query('api::blog.article').update({
where: { id: 1 },
data: {
title: 'xxx',
},
});
💡 Tip

In the data object, relations can be managed with the connect, disconnect, and set parameters using the syntax described for the REST API (see managing relations).

delete()

✏️ Note

Document Service delete() メソッドがあなたのユースケースをカバーできない場合にのみ、Query Engineのdelete()メソッドを使用してください。

1つのエントリを削除し、それを返します。

構文: delete(parameters) => Entry

パラメータ

パラメータタイプ説明
selectString, または文字列の配列返すべき属性
populatePopulateParameterpopulateする関係
whereWhereParameter使用するフィルター

const entry = await AI Marketer.db.query('api::blog.article').delete({
where: { id: 1 },
});