# new MethodQueryBuilder(methodName, values) → {QueryAssist}
The MethodQueryBuilder class parses method names that follow a specific naming convention
(e.g., findByNameAndAgeOrderByCountryAsc) and converts them into structured query objects
(QueryAssist). It extracts clauses such as select, where, groupBy, orderBy, limit,
and offset, ensuring that developers can declare repository queries using expressive method names.
Utility class to build query objects from repository method names.
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string
|
The repository method name to parse and convert into a query. |
values |
Array.<any>
|
The values corresponding to method parameters used for query conditions. |
A structured query object describing the parsed action, select, where, groupBy, orderBy, limit, and offset clauses.
QueryAssist
Example
```ts
const query = MethodQueryBuilder.build(
"findByNameAndAgeOrderByCountryAsc",
"John",
25,
[["country", "ASC"]]
);
console.log(query);
// {
// action: "find",
// select: undefined,
// where: { ... },
// groupBy: undefined,
// orderBy: [["country", "ASC"]],
// limit: undefined,
// offset: undefined
// }
```
Methods
# static build(methodName, values) → {QueryAssist}
The method validates the method name, extracts clauses (core, select, groupBy, where, orderBy, limit, and offset), and assembles them into a structured query object that can be executed against a data source.
Builds a QueryAssist object by parsing a repository method name and values.
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string
|
The repository method name that encodes query information. |
values |
Array.<any>
|
The values corresponding to conditions and extra clauses. |
A structured query object representing the parsed query.
QueryAssist
# static buildWhere(core, values) → {Condition.<any>}
Splits the core string by logical operators (And, Or), parses each token into a field
and operator, and combines them into a Condition object using the provided values.
Builds the where condition object based on the parsed core string and parameter values.
Parameters:
| Name | Type | Description |
|---|---|---|
core |
string
|
The extracted core string from the method name. |
values |
Array.<any>
|
The values corresponding to the conditions. |
A structured condition object representing the query's where clause.
Condition.<any>
# static extractCore(methodName) → {string}
Removes prefixes and detects delimiters (Then, OrderBy, GroupBy, Limit, Offset)
to isolate the main conditional part of the query.
Extracts the core part of the method name after findBy and before any special clauses.
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string
|
The method name to parse. |
The extracted core string used for building conditions.
string
# static extractGroupBy(methodName) → {Array.<string>|undefined}
Detects the GroupBy keyword in the method name, isolates the fields following it,
and returns them as an array of lowercase-first strings.
Extracts the group by clause from a method name.
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string
|
The method name to parse. |
An array of group by fields or undefined if no group by clause exists.
Array.<string>
|
undefined
# static extractOrderLimitOffset(core, values) → {OrderLimitOffsetExtract}
Determines the number of condition arguments, then checks the remaining arguments to resolve sorting, limiting, and pagination.
Extracts orderBy, limit, and offset clauses from method arguments.
Parameters:
| Name | Type | Description |
|---|---|---|
core |
string
|
The extracted core string from the method name. |
values |
Array.<any>
|
The values corresponding to method arguments, including conditions and extras. |
An object containing orderBy, limit, and offset values if present.
OrderLimitOffsetExtract
# static extractSelect(methodName) → {Array.<string>|undefined}
Detects the Select keyword in the method name, isolates the fields following it,
and returns them as an array of lowercase-first strings.
Extracts the select clause from a method name.
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string
|
The method name to parse. |
An array of selected fields or undefined if no select clause exists.
Array.<string>
|
undefined
# static parseFieldAndOperator(str) → {FilterDescriptor}
Identifies the operator suffix (if present) and returns a descriptor containing the field name in lowercase-first format along with the operator.
Parses a field name and operator from a string token.
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The token string to parse. |
An object containing the field name and operator.
FilterDescriptor