Constructor
new SelectQueryBuilder()
Represents a SelectQueryBuilder.
- Source
Extends
- QueryOptions
Methods
addJoins(query) → {string}
Adds joins to the query.
Name | Type | Description |
---|---|---|
query | string | The query to add joins to. |
- Source
The updated query with joins added.
- Type:
- string
addWhereClause(query) → {string}
Adds a WHERE clause to the query based on the specified conditions.
Name | Type | Description |
---|---|---|
query | string | The original query string. |
- Source
The modified query string with the WHERE clause added.
- Type:
- string
buildAggregateQuery() → {string}
Builds and returns the aggregate query based on the specified aggregates, table, conditions, group by, order by, limit, and offset.
- Source
The aggregate query.
- Type:
- string
buildQuery() → {Object}
Builds the query based on the specified table, aggregates, and values.
- Source
If no table is set.
- Type
- Error
If an error occurs while building the query.
- Type
- Error
An object containing the built query and the associated values.
- Type:
- Object
const queryBuilder = new SelectQueryBuilder();
queryBuilder.setTable('users')
.setFields('id, name, email')
.addCondition({ field: 'id', operator: '=', value: 1)
.addCondition({ conjunction: 'OR', field: 'name', operator: 'LIKE', value: '%John%' });
const { query, values } = queryBuilder.buildQuery();
console.log(query); // SELECT id, name, email FROM users WHERE id = $1 OR name LIKE $2
console.log(values); // [1, '%John%']
buildSelectQuery() → {string}
Builds and returns the SELECT query based on the current state of the SelectQueryBuilder.
- Source
The generated SELECT query.
- Type:
- string