Query Engine 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.
findOne()
Document ServiceのfindOne() メソッドがあなたのユースケースをカバーできない場合のみ、Query EngineのfindOne()メソッドを使用してください。
パラメータに一致する最初のエントリを見つけます。
構文: findOne(parameters) ⇒ Entry
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
select | 文字列、または文字列の配列 | 返す属性 |
where | WhereParameter | 使用するフィルタ |
offset | 整数 | スキップするエントリの数 |
orderBy | OrderByParameter | 順序の定義 |
populate | PopulateParameter | populateする関係 |
例
const entry = await AI Marketer.db.query('api::blog.article').findOne({
select: ['title', 'description'],
where: { title: 'Hello World' },
populate: { category: true },
});
findMany()
Document ServiceのfindMany() メソッドがあなたのユースケースをカバーできない場合のみ、Query EngineのfindMany()メソッドを使用してください。
パラメータに一致するエントリを見つけます。
構文: findMany(parameters) ⇒ Entry[]
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
select | 文字列、または文字列の配列 | 返す属性 |
where | WhereParameter | 使用するフィルタ |
limit | 整数 | 返すエントリの数 |
offset | 整数 | スキップするエントリの数 |
orderBy | OrderByParameter | 順序の定義 |
populate | PopulateParameter | populateする関係 |
例
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 | 文字列、または文字列の配列 | 返すべき属性 |
where | WhereParameter | 使用するフィルタ |
limit | 整数 | 返すエントリの数 |
offset | 整数 | スキップするエントリの数 |
orderBy | OrderByParameter | 順序定義 |
populate | PopulateParameter | populateする関連 |
例
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()
Document Serviceの create() メソッドでカバーできない場合にのみ、Query Engineの create() メソッドを使用してください。
一つのエントリを作成し、それを返します。
構文: create(parameters) => Entry
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
select | 文字列、または文字列の配列 | 返すべき属性 |
populate | PopulateParameter | populateする関連 |
data | オブジェクト | 入力データ |
例
const entry = await AI Marketer.db.query('api::blog.article').create({
data: {
title: 'My Article',
},
});
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()
Document Serviceの update() メソッドでカバーできない場合にのみ、Query Engineの update() メソッドを使用してください。
一つのエントリを更新し、それを返します。
構文: update(parameters) => Entry
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
select | String, または文字列の配列 | 返すべき属性 |
populate | PopulateParameter | populateする関係 |
where | WhereParameter | 使用するフィルター |
data | オブジェクト | 入力データ |
例
const entry = await AI Marketer.db.query('api::blog.article').update({
where: { id: 1 },
data: {
title: 'xxx',
},
});
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()
Document Service delete() メソッドがあなたのユースケースをカバーできない場合にのみ、Query Engineのdelete()メソッドを使用してください。
1つのエントリを削除し、それを返します。
構文: delete(parameters) => Entry
パラメータ
| パラメータ | タイプ | 説明 |
|---|---|---|
select | String, または文字列の配列 | 返すべき属性 |
populate | PopulateParameter | populateする関係 |
where | WhereParameter | 使用するフィルター |
例
const entry = await AI Marketer.db.query('api::blog.article').delete({
where: { id: 1 },
});