@areumtecnologia/mysql-db-handler 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/lib/databaseHandler.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ The `select` method allows you to build complex queries using an array of parame
|
|
|
74
74
|
* `params` (Array): An array where each element is either a condition object or a logical string ('AND', 'OR').
|
|
75
75
|
* Simple condition: `{ column: value }` (defaults to `=`)
|
|
76
76
|
* Condition with operator: `{ column: value, operator: '>' }`
|
|
77
|
-
* `clauses` (Object): Optional keys like `
|
|
77
|
+
* `clauses` (Object): Optional keys like `ORDERBY`, `DESC`, `LIMIT`, `OFFSET`, `GROUP BY`, `HAVING`.
|
|
78
78
|
|
|
79
79
|
**Example:**
|
|
80
80
|
|
|
@@ -90,7 +90,8 @@ const results = await products.select(
|
|
|
90
90
|
],
|
|
91
91
|
// 2. Clauses: SQL Modifiers
|
|
92
92
|
{
|
|
93
|
-
'
|
|
93
|
+
'ORDERBY': 'price',
|
|
94
|
+
'DESC': true,
|
|
94
95
|
'LIMIT': 10,
|
|
95
96
|
'OFFSET': 0
|
|
96
97
|
}
|
package/lib/databaseHandler.js
CHANGED
|
@@ -199,10 +199,11 @@ class DatabaseHandler {
|
|
|
199
199
|
const groupByClause = clauses['GROUPBY'] ? ` GROUP BY ${clauses['GROUPBY']}` : '';
|
|
200
200
|
const havingClause = clauses['HAVING'] ? ` HAVING ${clauses['HAVING']}` : '';
|
|
201
201
|
const orderClause = clauses['ORDERBY'] ? ` ORDER BY ${clauses['ORDERBY']}` : '';
|
|
202
|
+
const descClause = clauses['DESC'] ? ` DESC ` : '';
|
|
202
203
|
const limitClause = clauses['LIMIT'] ? ` LIMIT ${clauses['LIMIT']}` : '';
|
|
203
204
|
const offsetClause = clauses['OFFSET'] ? ` OFFSET ${clauses['OFFSET']}` : '';
|
|
204
205
|
|
|
205
|
-
const sql = `SELECT *${this.expression ?? ''} FROM ${this.table}${whereClause}${groupByClause}${havingClause}${orderClause}${limitClause}${offsetClause}`;
|
|
206
|
+
const sql = `SELECT *${this.expression ?? ''} FROM ${this.table}${whereClause}${groupByClause}${havingClause}${orderClause}${descClause}${limitClause}${offsetClause}`;
|
|
206
207
|
|
|
207
208
|
const rows = await this.executeQuery(sql, values);
|
|
208
209
|
return rows;
|
package/package.json
CHANGED