@areumtecnologia/mysql-db-handler 1.0.2 → 1.0.4
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 +24 -2
- package/desktop.ini +0 -0
- package/lib/databaseHandler.js +2 -1
- package/lib/desktop.ini +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,6 +66,27 @@ const activeCustomers = await customers.selectBy({ status: 1 });
|
|
|
66
66
|
|
|
67
67
|
## Advanced Usage & Examples
|
|
68
68
|
|
|
69
|
+
### Inserting Records (`insert`)
|
|
70
|
+
|
|
71
|
+
The `insert` method adds a new row to the table.
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
* `params` (Object): An object where keys match the column names and values are the data to insert.
|
|
75
|
+
|
|
76
|
+
**Example:**
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const logs = new DataBaseHandler(db, 'app_logs');
|
|
80
|
+
|
|
81
|
+
const result = await logs.insert({
|
|
82
|
+
level: 'info',
|
|
83
|
+
message: 'User logged in',
|
|
84
|
+
timestamp: new Date()
|
|
85
|
+
});
|
|
86
|
+
// Executes: INSERT INTO app_logs SET `level` = ?, `message` = ?, `timestamp` = ?
|
|
87
|
+
console.log(`Inserted Row ID: ${result.insertId}`);
|
|
88
|
+
```
|
|
89
|
+
|
|
69
90
|
### Flexible Selection (`select`)
|
|
70
91
|
|
|
71
92
|
The `select` method allows you to build complex queries using an array of parameters and a clauses object.
|
|
@@ -74,7 +95,7 @@ The `select` method allows you to build complex queries using an array of parame
|
|
|
74
95
|
* `params` (Array): An array where each element is either a condition object or a logical string ('AND', 'OR').
|
|
75
96
|
* Simple condition: `{ column: value }` (defaults to `=`)
|
|
76
97
|
* Condition with operator: `{ column: value, operator: '>' }`
|
|
77
|
-
* `clauses` (Object): Optional keys like `
|
|
98
|
+
* `clauses` (Object): Optional keys like `ORDERBY`, `DESC`, `LIMIT`, `OFFSET`, `GROUP BY`, `HAVING`.
|
|
78
99
|
|
|
79
100
|
**Example:**
|
|
80
101
|
|
|
@@ -90,7 +111,8 @@ const results = await products.select(
|
|
|
90
111
|
],
|
|
91
112
|
// 2. Clauses: SQL Modifiers
|
|
92
113
|
{
|
|
93
|
-
'
|
|
114
|
+
'ORDERBY': 'price',
|
|
115
|
+
'DESC': true,
|
|
94
116
|
'LIMIT': 10,
|
|
95
117
|
'OFFSET': 0
|
|
96
118
|
}
|
package/desktop.ini
ADDED
|
Binary file
|
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/lib/desktop.ini
ADDED
|
Binary file
|
package/package.json
CHANGED