@aceitadev/adatabase 0.2.0 → 0.2.5

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.
@@ -4,6 +4,7 @@ type Constructor<T> = {
4
4
  new (...args: any[]): T;
5
5
  };
6
6
  export declare abstract class ActiveRecord {
7
+ private static idFieldCache;
7
8
  private static getIdField;
8
9
  save<T extends ActiveRecord>(this: T, tx?: GenericConnection): Promise<T>;
9
10
  static find<T extends ActiveRecord>(this: Constructor<T>): QueryBuilder<T>;
@@ -21,11 +21,15 @@ function camelToSnake(s) {
21
21
  class ActiveRecord {
22
22
  static getIdField(ctor) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
+ if (this.idFieldCache.has(ctor)) {
25
+ return this.idFieldCache.get(ctor);
26
+ }
24
27
  const columns = (0, Column_1.getColumnMeta)(ctor);
25
28
  if (!columns)
26
29
  throw new PersistenceException_1.PersistenceException("Model has no @Column decorators", null);
27
30
  for (const [prop, opts] of columns.entries()) {
28
31
  if (opts === null || opts === void 0 ? void 0 : opts.id) {
32
+ this.idFieldCache.set(ctor, prop);
29
33
  return prop;
30
34
  }
31
35
  }
@@ -119,3 +123,4 @@ ${idColName}
119
123
  }
120
124
  }
121
125
  exports.ActiveRecord = ActiveRecord;
126
+ ActiveRecord.idFieldCache = new Map();
@@ -59,6 +59,10 @@ class PostgresAdapter {
59
59
  const conn = connection !== null && connection !== void 0 ? connection : this.getPool();
60
60
  let pgSql = this.quoteIdentifiers(this.formatSql(sql));
61
61
  if (pgSql.trim().toUpperCase().startsWith('INSERT')) {
62
+ pgSql = pgSql.trim();
63
+ if (pgSql.endsWith(';')) {
64
+ pgSql = pgSql.slice(0, -1);
65
+ }
62
66
  pgSql += ' RETURNING id';
63
67
  }
64
68
  const result = yield conn.query(pgSql, params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aceitadev/adatabase",
3
- "version": "0.2.0",
3
+ "version": "0.2.5",
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",