UNPKG

@cubicweb/rql-generator

Version:

Helpers to build RQL queries

55 lines 2.49 kB
import { EntityRawSchemaArray, RelationDefinitionRawSchemaArray, RQLQuery, Schema } from "@cubicweb/client"; import { RqlQuerySelectOptions, RqlQueryWhere } from "./utils/types.js"; /** * Generates a SELECT RQL query to fetch a list of entities with the given attributes. * * @example * For a BlogEntry entity with the attributes `title`, `content` and relation `entry_of`. * Requesting the first 10 elements, sorted by ascending `title`. * ```typescript * generateSelectEntitiesRQL( * SCHEMA, * "BlogEntry", * { * limit: 10, * offset: 0, * orderBy: [{relationName: "title", ascending: true}], * resolve: ["title", "content", "entry_of"], * } * ) * ``` * produces: * ``` * Any X, ATTR_TITLE, ATTR_CONTENT, GROUP_CONCAT(REL_ENTRY_OF) GROUPBY X, ATTR_TITLE, ATTR_CONTENT ORDERBY ATTR_TITLE ASC LIMIT 10 OFFSET 0 WHERE X is BlogEntry, X title ATTR_TITLE, X content ATTR_CONTENT, X entry_of REL_ENTRY_OF * ``` * * @param schema This CW instance's schema * @param entityType The type of entity to fetch * @param rqlQueryListOptions Options to build the RQL query * @returns An array of RQL queries to fetch entities with the given attributes/relations. The produced {@link ResultSet} contains values for the resolved attributes/relations in the same order as the passed `resolve` option. * * @category Getting entities */ export declare function generateSelectEntitiesRQL<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E>>(schema: Schema<E, R>, entityType: string, { limit, offset, orderBy, where, relations }: RqlQuerySelectOptions): RQLQuery[]; /** * Generates a RQL query to count the number of entities respecting the given filter. * * @example * Counting the number of BlogEntry in a given Blog: * ```typescript * generateCountEntitiesRQL(SCHEMA, "BlogEntry", {where: {entry_of: 12498}}) * ``` * produces: * ``` * Any Count(X) WHERE X is BlogEntry, X entry_of %(entry_of)s * ``` * * @param schema This CW instance's schema * @param entityType The type of entity to count * @param where A custom filter * @returns An array of RQL queries to count the number of entities respecting the given filter * * @category Getting entities */ export declare function generateCountEntitiesRQL<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E>>(schema: Schema<E, R>, entityType: string, { where }: RqlQueryWhere): RQLQuery[]; //# sourceMappingURL=get.d.ts.map