Récupérer une entité
8 min
Vue d’ensemble
Chaque entité dispose de trois fonctions pour la recherche :
- $[EntityName] : le type de retour est null | T | T[] ;
- list[EntityName] : le type de retour est null | T[] ;
- get[EntityName] : le type de retour est null | T.
Recherche d'entités par leur type
// Search for all `Project` entities
await $Project({}); // result is: null | T | T[]
await $Project({}, { list: true }); // result is: T[]
await listProject(); // result is: T[]
// Search for all `Company` entities linked to `project` entity
await $Company(project, {}); // result is: null | T | T[]
await $Company(project, {}, { list: true }); // result is: T[]
await listCompany(project); // result is: T[]Recherche d'entités par leur identifiant
// Search for the `Project` entity with given id
await $Project(projectId); // result is: null | T
await getProject(projectId); // result is: null | T
// Search for the `Company` entity with given id
await $Company(project, companyId); // result is: null | T
await getCompany(project, companyId); // result is: null | TRecherche d'entités par des critères simples
// Search for all `Project` entities
// having 'status' equals to 'created'
await $Project({ status: 'created' }); // result is: null | T | T[]
await listProject({ status: 'created' }); // result is: null | T | T[]
// Search for the `Project` entity
// having 'externalId' equals to '1234'
await getProject({ externalId: '1234' }); // result is: null | T
// Search for all `Company` entities linked to `project` entity
// having 'name' equals to 'foo'
await $Company(project, { name: 'foo' }); // result is: null | T | T[]
await listCompany(project, { name: 'foo' }); // result is: null | T | T[]
// Search for the `Company` entity linked to `project` entity
// having 'externalId' equals to '1234'
await getCompany(project, { externalId: '1234' }); // result is: null | TRecherche d'entités par des critères avancés
// Search for all `Project` entities
// satisfying predicate: `$Project.key` != `value`
await $Project({ $search: { from: ['!=', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` < `value`
await $Project({ $search: { from: ['<', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` <= `value`
await $Project({ $search: { from: ['<=', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` > `value`
await $Project({ $search: { from: ['>', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` >= `value`
await $Project({ $search: { from: ['>=', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` like `value`
await $Project({ $search: { from: ['~~', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` like `value` (case ignored)
await $Project({ $search: { from: ['~~*', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` not like `value`
await $Project({ $search: { from: ['!~~', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` not like `value` (case ignored)
await $Project({ $search: { from: ['!~~*', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` in `value`
await $Project({ $search: { from: ['in', 'key', value] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` != `value1` and `$Project.key` != `value2`
await $Project({ $search: { from: ['&&', ['!=', 'key', value1], ['!=', 'key', value2]] } });
// Search for all `Project` entities
// satisfying predicate: `$Project.key` != `value1` or `$Project.key` != `value2`
await $Project({ $search: { from: ['||', ['!=', 'key', value1], ['!=', 'key', value2]] } });
// Search for all `Company` entities
// satisfying predicate: `$Company.key` != `value`
await $Company(project, { $search: { from: ['!=', 'key', value] } });L'expression pour $search.from est définie par :
from_expr =
| ['&&', from_expr]
| ['||', from_expr]
| [op, key, value]Opérateurs disponibles
Considérant l'expression [op, 'key', value], op correspond à l'une des valeurs suivantes :
- == : la valeur de la propriété key est égale à value ;
- != : la valeur de la propriété key est différente de value ;
- < : la valeur de la propriété key est strictement inférieure à value ;
- <= : la valeur de la propriété key est inférieure ou égale à value ;
- > : la valeur de la propriété key est strictement supérieure à value ;
- >= : la valeur de la propriété key est supérieure ou égale à value ;
- ~~ : la valeur de la propriété key correspond à l'expression régulière value ;
- ~~* : la valeur de la propriété key correspond à l'expression régulière value (casse ignorée) ;
- !~~ : la valeur de la propriété key ne correspond pas à l'expression régulière value ;
- !~~* : la valeur de la propriété key ne correspond pas à l'expression régulière value (casse ignorée) ;
- in : la valeur de la propriété key est égale à l'une des valeurs présentes dans la liste value.
Recherche d'entités par des critères sur leurs sous-entités
Info
Ce type de recherche n'est disponible que pour l'entité racine Project.
// Search for all `Project` entities
// satisfying predicate: `$Project.status` == `status`
// and having a direct `Customer` entity satisfying predicate:
// `$Customer.lastName` == `lastName`
await $Project({
$search: {
from: ['==', 'status', status],
with: [['Customer'], [['==', 'lastName', lastName]]]
}
});
// Search for all `Project` entities
// satisfying predicate: `$Project.status` == `status`
// and having a direct `Customer` entity satisfying predicate:
// `$Customer.lastName` == `lastName`
// and having a direct `Address` entity satisfying predicate:
// `$Address.street` == `street`
await $Project({
$search: {
from: ['==', 'status', status],
with: [['Customer', 'Address'], [['==', 'lastName', lastName], ['==', 'street', street]]]
}
});
// Search for all `Project` entities
// having either a direct `Customer` entity satisfying predicate:
// `$Customer.lastName` like `lastName` or
// `$Customer.firstName` like `firstName` or
// `$Customer.email` like `email`
// or a direct `Policy` entity satisfying predicate:
// `$Policy.externalId` like `externalId`
await $Project({
$search: {
with: [
'||',
[['Customer'], [['||', ['~~', 'lastName', lastName], ['~~', 'firstName', firstName], ['~~', 'email', email]]]],
[['Policy'], [['~~', 'externalId', externalId]]]
]
}
});
// Search for all `Project` entities
// having either
// a direct `Customer` entity satisfying predicate:
// `$Customer.lastName` like `lastName` or
// `$Customer.firstName` like `firstName` or
// `$Customer.email` like `email`
// and a direct `Grantee` entity satisfying predicate:
// `$Grantee.lastName` == `lastName`
// or a direct `Policy` entity satisfying predicate:
// `$Policy.externalId` like `externalId`
await $Project({
$search: {
with: [
'||',
[
'&&',
[['Customer'], [['||', ['~~', 'lastName', lastName], ['~~', 'firstName', firstName], ['~~', 'email', email]]]],
[['Grantee'], [['==', 'lastName', lastName]]]
],
[['Policy'], [['~~', 'externalId', externalId]]]
]
}
});L'expression pour $search.with est définie par :
with_expr =
| ['&&', with_expr]
| ['||', with_expr]
| [[path_expr], [from_expr]]À noter que :
- path_expr est une liste de types d'entités ;
- from_expr est l'expression définie précédemment pour $search.from ;
- path_expr et from_expr doivent avoir le même nombre d'éléments.