@travetto/model-mysql 5.0.17 → 5.0.18

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mysql",
3
- "version": "5.0.17",
3
+ "version": "5.0.18",
4
4
  "description": "MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
5
5
  "keywords": [
6
6
  "sql",
@@ -27,13 +27,13 @@
27
27
  "directory": "module/model-mysql"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/cli": "^5.0.16",
31
- "@travetto/config": "^5.0.13",
32
- "@travetto/context": "^5.0.13",
33
- "@travetto/model": "^5.0.14",
34
- "@travetto/model-query": "^5.0.14",
35
- "@travetto/model-sql": "^5.0.17",
36
- "mysql2": "^3.11.3"
30
+ "@travetto/cli": "^5.0.17",
31
+ "@travetto/config": "^5.0.14",
32
+ "@travetto/context": "^5.0.14",
33
+ "@travetto/model": "^5.0.15",
34
+ "@travetto/model-query": "^5.0.15",
35
+ "@travetto/model-sql": "^5.0.18",
36
+ "mysql2": "^3.11.5"
37
37
  },
38
38
  "travetto": {
39
39
  "displayName": "MySQL Model Service"
package/src/connection.ts CHANGED
@@ -59,10 +59,12 @@ export class MySQLConnection extends Connection<PoolConnection> {
59
59
  return res;
60
60
  }
61
61
 
62
- async execute<T = unknown>(conn: PoolConnection, query: string): Promise<{ count: number, records: T[] }> {
62
+ async execute<T = unknown>(conn: PoolConnection, query: string, values?: unknown[]): Promise<{ count: number, records: T[] }> {
63
63
  console.debug('Executing Query', { query });
64
+ let prepared;
64
65
  try {
65
- const [results,] = await conn.query(query);
66
+ prepared = (values?.length ?? 0) > 0 ? await conn.prepare(query) : undefined;
67
+ const [results,] = await (prepared ? prepared.execute(values) : conn.query(query));
66
68
  if (isSimplePacket(results)) {
67
69
  return { records: [], count: results.affectedRows };
68
70
  } else {
@@ -79,6 +81,10 @@ export class MySQLConnection extends Connection<PoolConnection> {
79
81
  } else {
80
82
  throw err;
81
83
  }
84
+ } finally {
85
+ try {
86
+ await prepared?.close();
87
+ } catch { }
82
88
  }
83
89
  }
84
90