@mikro-orm/sql 7.2.9-dev.21 → 7.2.9-dev.23

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.
@@ -78,6 +78,7 @@ export declare class BasePostgreSqlPlatform extends AbstractSqlPlatform {
78
78
  /**
79
79
  * Ported from PostgreSQL 9.2.4 source code (`src/interfaces/libpq/fe-exec.c`),
80
80
  * matching `pg.Client.prototype.escapeLiteral` so we don't need a `pg` dep here.
81
+ * Avoids per-character concatenation (builds a rope, slow on large values) and regexps (fixed cost on tiny values).
81
82
  */
82
83
  private escapeLiteral;
83
84
  getVarcharTypeDeclarationSQL(column: {
@@ -273,28 +273,22 @@ export class BasePostgreSqlPlatform extends AbstractSqlPlatform {
273
273
  /**
274
274
  * Ported from PostgreSQL 9.2.4 source code (`src/interfaces/libpq/fe-exec.c`),
275
275
  * matching `pg.Client.prototype.escapeLiteral` so we don't need a `pg` dep here.
276
+ * Avoids per-character concatenation (builds a rope, slow on large values) and regexps (fixed cost on tiny values).
276
277
  */
277
278
  escapeLiteral(str) {
278
- let hasBackslash = false;
279
- let escaped = `'`;
280
- for (let i = 0; i < str.length; i++) {
281
- const c = str[i];
282
- if (c === `'`) {
283
- escaped += c + c;
284
- }
285
- else if (c === '\\') {
286
- escaped += c + c;
287
- hasBackslash = true;
288
- }
289
- else {
290
- escaped += c;
291
- }
279
+ const hasBackslash = str.includes('\\');
280
+ const hasQuote = str.includes(`'`);
281
+ if (!hasBackslash && !hasQuote) {
282
+ return `'${str}'`;
292
283
  }
293
- escaped += `'`;
284
+ let escaped = str;
294
285
  if (hasBackslash) {
295
- escaped = ` E${escaped}`;
286
+ escaped = escaped.replaceAll('\\', '\\\\');
287
+ }
288
+ if (hasQuote) {
289
+ escaped = escaped.replaceAll(`'`, `''`);
296
290
  }
297
- return escaped;
291
+ return hasBackslash ? ` E'${escaped}'` : `'${escaped}'`;
298
292
  }
299
293
  getVarcharTypeDeclarationSQL(column) {
300
294
  if (column.length === -1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.9-dev.21",
3
+ "version": "7.2.9-dev.23",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.8"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.9-dev.21"
56
+ "@mikro-orm/core": "7.2.9-dev.23"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"