@aceitadev/adatabase 0.1.2 → 0.1.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.
@@ -58,8 +58,10 @@ class ActiveRecord {
58
58
  if (idValue == null || idValue === 0) {
59
59
  const cols = colEntries.map(c => `\`${c.colName}\``).join(", ");
60
60
  const placeholders = colEntries.map(() => "?").join(", ");
61
- const params = colEntries.map(c => c.value);
62
- const sql = `INSERT INTO \`${table}\` (${cols}) VALUES (${placeholders});`;
61
+ const params = colEntries.map(c => c.value === undefined ? null : c.value);
62
+ const sql = `INSERT INTO
63
+ ${table}
64
+ (${cols}) VALUES (${placeholders});`;
63
65
  const res = yield (0, Database_1.execute)(sql, params, conn);
64
66
  if (res.insertId) {
65
67
  this[idField] = res.insertId;
@@ -67,9 +69,13 @@ class ActiveRecord {
67
69
  }
68
70
  else {
69
71
  const setClause = colEntries.map(c => `\`${c.colName}\` = ?`).join(", ");
70
- const params = [...colEntries.map(c => c.value), idValue];
72
+ const params = [...colEntries.map(c => c.value === undefined ? null : c.value), idValue];
71
73
  const idColName = camelToSnake(idField);
72
- const sql = `UPDATE \`${table}\` SET ${setClause} WHERE \`${idColName}\` = ?;`;
74
+ const sql = `UPDATE
75
+ ${table}
76
+ SET ${setClause} WHERE
77
+ ${idColName}
78
+ = ?;`;
73
79
  yield (0, Database_1.execute)(sql, params, conn);
74
80
  }
75
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aceitadev/adatabase",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Uma biblioteca para facilitar a interação com bancos de dados MySQL e PostgreSQL em projetos TypeScript/Node.js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",