@areumtecnologia/mysql-db-handler 1.0.0 → 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 +4 -3
- 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
|
@@ -196,13 +196,14 @@ class DatabaseHandler {
|
|
|
196
196
|
const whereClause = conditions.length > 0 ? ` WHERE ${conditions.join(' ')}` : '';
|
|
197
197
|
|
|
198
198
|
// Cláusulas adicionais
|
|
199
|
-
const groupByClause = clauses['GROUPBY'] ? ` GROUP BY ${clauses['
|
|
199
|
+
const groupByClause = clauses['GROUPBY'] ? ` GROUP BY ${clauses['GROUPBY']}` : '';
|
|
200
200
|
const havingClause = clauses['HAVING'] ? ` HAVING ${clauses['HAVING']}` : '';
|
|
201
|
-
const orderClause = clauses['ORDERBY'] ? ` ORDER BY ${clauses['
|
|
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