@platformatic/sql-mapper 1.3.1 → 1.4.0

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.
Files changed (3) hide show
  1. package/mapper.d.ts +21 -0
  2. package/mapper.js +9 -6
  3. package/package.json +2 -2
package/mapper.d.ts CHANGED
@@ -311,6 +311,27 @@ interface BasePoolOptions {
311
311
  * @default 10
312
312
  */
313
313
  poolSize?: number
314
+
315
+ /**
316
+ * Max milliseconds a client can go unused before it is removed from the pool and destroyed
317
+ * Default is 30_000ms
318
+ * @default 30000
319
+ */
320
+ idleTimeoutMilliseconds?: number
321
+
322
+ /**
323
+ * Number of milliseconds to wait for a connection from the connection pool before throwing a timeout error
324
+ * Default is 60_000ms
325
+ * @default 60000
326
+ */
327
+ queueTimeoutMilliseconds?: number
328
+
329
+ /**
330
+ * Number of milliseconds to wait for a lock on a connection/transaction.
331
+ * Default is 60_000ms
332
+ * @default 60000
333
+ */
334
+ acquireLockTimeoutMilliseconds?: number
314
335
  }
315
336
 
316
337
  export interface CreateConnectionPoolOptions extends BasePoolOptions {
package/mapper.js CHANGED
@@ -11,11 +11,14 @@ const setupCache = require('./lib/cache')
11
11
 
12
12
  // Ignore the function as it is only used only for MySQL and PostgreSQL
13
13
  /* istanbul ignore next */
14
- async function buildConnection (log, createConnectionPool, connectionString, poolSize, schema) {
14
+ async function buildConnection (log, createConnectionPool, connectionString, poolSize, schema, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds) {
15
15
  const db = await createConnectionPool({
16
16
  connectionString,
17
17
  bigIntMode: 'string',
18
18
  poolSize,
19
+ idleTimeoutMilliseconds,
20
+ queueTimeoutMilliseconds,
21
+ acquireLockTimeoutMilliseconds,
19
22
  onQueryStart: (_query, { text, values }) => {
20
23
  log.trace({
21
24
  query: {
@@ -50,7 +53,7 @@ const defaultAutoTimestampFields = {
50
53
  updatedAt: 'updated_at'
51
54
  }
52
55
 
53
- async function createConnectionPool ({ log, connectionString, poolSize }) {
56
+ async function createConnectionPool ({ log, connectionString, poolSize, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds }) {
54
57
  let db
55
58
  let sql
56
59
 
@@ -59,12 +62,12 @@ async function createConnectionPool ({ log, connectionString, poolSize }) {
59
62
  /* istanbul ignore next */
60
63
  if (connectionString.indexOf('postgres') === 0) {
61
64
  const createConnectionPoolPg = require('@databases/pg')
62
- db = await buildConnection(log, createConnectionPoolPg, connectionString, poolSize)
65
+ db = await buildConnection(log, createConnectionPoolPg, connectionString, poolSize, null, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds)
63
66
  sql = createConnectionPoolPg.sql
64
67
  db.isPg = true
65
68
  } else if (connectionString.indexOf('mysql') === 0) {
66
69
  const createConnectionPoolMysql = require('@databases/mysql')
67
- db = await buildConnection(log, createConnectionPoolMysql, connectionString, poolSize)
70
+ db = await buildConnection(log, createConnectionPoolMysql, connectionString, poolSize, null, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds)
68
71
  sql = createConnectionPoolMysql.sql
69
72
  const version = (await db.query(sql`SELECT VERSION()`))[0]['VERSION()']
70
73
  db.version = version
@@ -98,7 +101,7 @@ async function createConnectionPool ({ log, connectionString, poolSize }) {
98
101
  return { db, sql }
99
102
  }
100
103
 
101
- async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignore = {}, autoTimestamp = true, hooks = {}, schema, limit = {}, dbschema, cache }) {
104
+ async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignore = {}, autoTimestamp = true, hooks = {}, schema, limit = {}, dbschema, cache, idleTimeoutMilliseconds, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds }) {
102
105
  if (typeof autoTimestamp === 'boolean' && autoTimestamp === true) {
103
106
  autoTimestamp = defaultAutoTimestampFields
104
107
  }
@@ -108,7 +111,7 @@ async function connect ({ connectionString, log, onDatabaseLoad, poolSize, ignor
108
111
  }
109
112
 
110
113
  let queries
111
- const { db, sql } = await createConnectionPool({ log, connectionString, poolSize })
114
+ const { db, sql } = await createConnectionPool({ log, connectionString, poolSize, queueTimeoutMilliseconds, acquireLockTimeoutMilliseconds, idleTimeoutMilliseconds })
112
115
 
113
116
  /* istanbul ignore next */
114
117
  if (db.isPg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
6
  "types": "mapper.d.ts",
@@ -32,7 +32,7 @@
32
32
  "camelcase": "^6.3.0",
33
33
  "fastify-plugin": "^4.5.1",
34
34
  "inflected": "^2.1.0",
35
- "@platformatic/utils": "1.3.1"
35
+ "@platformatic/utils": "1.4.0"
36
36
  },
37
37
  "tsd": {
38
38
  "directory": "test/types"