velocious 1.0.727 → 1.0.729

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 (112) hide show
  1. package/README.md +2 -2
  2. package/bin/velocious.js +2 -19
  3. package/build/application.js +32 -3
  4. package/build/background-jobs/main.js +9 -1
  5. package/build/background-jobs/worker.js +69 -6
  6. package/build/bin/velocious.js +2 -19
  7. package/build/cli/process-args.js +34 -0
  8. package/build/configuration.js +26 -0
  9. package/build/database/database-name.js +25 -0
  10. package/build/database/drivers/base.js +60 -12
  11. package/build/database/drivers/mssql/index.js +27 -18
  12. package/build/database/drivers/mssql/table.js +28 -25
  13. package/build/database/drivers/mysql/index.js +25 -18
  14. package/build/database/drivers/mysql/table.js +31 -23
  15. package/build/database/drivers/pgsql/index.js +25 -18
  16. package/build/database/drivers/pgsql/table.js +28 -26
  17. package/build/database/drivers/sqlite/base.js +20 -9
  18. package/build/database/drivers/sqlite/table.js +32 -26
  19. package/build/database/pool/async-tracked-multi-connection.js +1 -0
  20. package/build/database/pool/base.js +14 -4
  21. package/build/database/pool/single-multi-use.js +1 -0
  22. package/build/database/query/model-class-query.js +85 -0
  23. package/build/database/record/index.js +33 -0
  24. package/build/environment-handlers/node/cli/commands/server.js +1 -0
  25. package/build/http-server/server-lock.js +28 -4
  26. package/build/src/application.d.ts +7 -4
  27. package/build/src/application.d.ts.map +1 -1
  28. package/build/src/application.js +27 -4
  29. package/build/src/background-jobs/main.d.ts +2 -1
  30. package/build/src/background-jobs/main.d.ts.map +1 -1
  31. package/build/src/background-jobs/main.js +10 -2
  32. package/build/src/background-jobs/worker.d.ts +42 -0
  33. package/build/src/background-jobs/worker.d.ts.map +1 -1
  34. package/build/src/background-jobs/worker.js +61 -5
  35. package/build/src/cli/process-args.d.ts +11 -0
  36. package/build/src/cli/process-args.d.ts.map +1 -0
  37. package/build/src/cli/process-args.js +34 -0
  38. package/build/src/configuration.d.ts +13 -0
  39. package/build/src/configuration.d.ts.map +1 -1
  40. package/build/src/configuration.js +22 -1
  41. package/build/src/database/database-name.d.ts +9 -0
  42. package/build/src/database/database-name.d.ts.map +1 -0
  43. package/build/src/database/database-name.js +23 -0
  44. package/build/src/database/drivers/base.d.ts +31 -2
  45. package/build/src/database/drivers/base.d.ts.map +1 -1
  46. package/build/src/database/drivers/base.js +56 -13
  47. package/build/src/database/drivers/mssql/index.d.ts +7 -2
  48. package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
  49. package/build/src/database/drivers/mssql/index.js +25 -18
  50. package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
  51. package/build/src/database/drivers/mssql/table.js +25 -23
  52. package/build/src/database/drivers/mysql/index.d.ts +7 -2
  53. package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
  54. package/build/src/database/drivers/mysql/index.js +24 -19
  55. package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
  56. package/build/src/database/drivers/mysql/table.js +27 -22
  57. package/build/src/database/drivers/pgsql/index.d.ts +7 -2
  58. package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
  59. package/build/src/database/drivers/pgsql/index.js +24 -19
  60. package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
  61. package/build/src/database/drivers/pgsql/table.js +25 -23
  62. package/build/src/database/drivers/sqlite/base.d.ts +8 -0
  63. package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
  64. package/build/src/database/drivers/sqlite/base.js +19 -10
  65. package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
  66. package/build/src/database/drivers/sqlite/table.js +29 -25
  67. package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
  68. package/build/src/database/pool/async-tracked-multi-connection.js +2 -1
  69. package/build/src/database/pool/base.d.ts +6 -0
  70. package/build/src/database/pool/base.d.ts.map +1 -1
  71. package/build/src/database/pool/base.js +14 -5
  72. package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
  73. package/build/src/database/pool/single-multi-use.js +2 -1
  74. package/build/src/database/query/model-class-query.d.ts +20 -0
  75. package/build/src/database/query/model-class-query.d.ts.map +1 -1
  76. package/build/src/database/query/model-class-query.js +75 -1
  77. package/build/src/database/record/index.d.ts +46 -0
  78. package/build/src/database/record/index.d.ts.map +1 -1
  79. package/build/src/database/record/index.js +30 -1
  80. package/build/src/environment-handlers/node/cli/commands/server.d.ts.map +1 -1
  81. package/build/src/environment-handlers/node/cli/commands/server.js +2 -1
  82. package/build/src/http-server/server-lock.d.ts +23 -5
  83. package/build/src/http-server/server-lock.d.ts.map +1 -1
  84. package/build/src/http-server/server-lock.js +27 -5
  85. package/build/src/tenants/default-tenant-database-provisioning.d.ts +14 -0
  86. package/build/src/tenants/default-tenant-database-provisioning.d.ts.map +1 -1
  87. package/build/src/tenants/default-tenant-database-provisioning.js +31 -17
  88. package/build/tenants/default-tenant-database-provisioning.js +33 -19
  89. package/package.json +2 -2
  90. package/src/application.js +32 -3
  91. package/src/background-jobs/main.js +9 -1
  92. package/src/background-jobs/worker.js +69 -6
  93. package/src/cli/process-args.js +34 -0
  94. package/src/configuration.js +26 -0
  95. package/src/database/database-name.js +25 -0
  96. package/src/database/drivers/base.js +60 -12
  97. package/src/database/drivers/mssql/index.js +27 -18
  98. package/src/database/drivers/mssql/table.js +28 -25
  99. package/src/database/drivers/mysql/index.js +25 -18
  100. package/src/database/drivers/mysql/table.js +31 -23
  101. package/src/database/drivers/pgsql/index.js +25 -18
  102. package/src/database/drivers/pgsql/table.js +28 -26
  103. package/src/database/drivers/sqlite/base.js +20 -9
  104. package/src/database/drivers/sqlite/table.js +32 -26
  105. package/src/database/pool/async-tracked-multi-connection.js +1 -0
  106. package/src/database/pool/base.js +14 -4
  107. package/src/database/pool/single-multi-use.js +1 -0
  108. package/src/database/query/model-class-query.js +85 -0
  109. package/src/database/record/index.js +33 -0
  110. package/src/environment-handlers/node/cli/commands/server.js +1 -0
  111. package/src/http-server/server-lock.js +28 -4
  112. package/src/tenants/default-tenant-database-provisioning.js +33 -19
@@ -64,7 +64,7 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
64
64
  }
65
65
 
66
66
  async getColumns() {
67
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
67
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
68
68
  const result = await this.driver.query(`
69
69
  SELECT
70
70
  columns.*,
@@ -86,20 +86,21 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
86
86
  keyColumnUsage.COLUMN_NAME = columns.COLUMN_NAME
87
87
  WHERE columns.TABLE_NAME = ${this.driver.quote(this.getName())}
88
88
  `)
89
- const columns = []
89
+ return result
90
+ })
91
+ const columns = []
90
92
 
91
- for (const data of result) {
92
- const column = new Column(this, data)
93
+ for (const data of columnRows) {
94
+ const column = new Column(this, data)
93
95
 
94
- columns.push(column)
95
- }
96
+ columns.push(column)
97
+ }
96
98
 
97
- return columns
98
- })
99
+ return columns
99
100
  }
100
101
 
101
102
  async getForeignKeys() {
102
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
103
+ const foreignKeyRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
103
104
  const sql = `
104
105
  SELECT
105
106
  fk.name AS CONSTRAINT_NAME,
@@ -125,21 +126,21 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
125
126
  ORDER BY CONSTRAINT_NAME, ParentTable, ReferencedTable;
126
127
  `
127
128
 
128
- const foreignKeyRows = await this.driver.query(sql)
129
- const foreignKeys = []
129
+ return await this.driver.query(sql)
130
+ })
131
+ const foreignKeys = []
130
132
 
131
- for (const foreignKeyRow of foreignKeyRows) {
132
- const foreignKey = new ForeignKey(foreignKeyRow)
133
+ for (const foreignKeyRow of foreignKeyRows) {
134
+ const foreignKey = new ForeignKey(foreignKeyRow)
133
135
 
134
- foreignKeys.push(foreignKey)
135
- }
136
+ foreignKeys.push(foreignKey)
137
+ }
136
138
 
137
- return foreignKeys
138
- })
139
+ return foreignKeys
139
140
  }
140
141
 
141
142
  async getIndexes() {
142
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
143
+ const groupedIndexRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
143
144
  const options = this.getOptions()
144
145
  const sql = `
145
146
  SELECT
@@ -161,17 +162,19 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
161
162
  `
162
163
 
163
164
  const rows = await this.getDriver().query(sql)
164
- const indexes = []
165
165
  const indexRows = rows.map((row) => normalizeIndexMetadataRow(row))
166
166
 
167
- for (const indexData of groupMssqlIndexRows(indexRows)) {
168
- const index = new ColumnsIndex(this, indexData)
167
+ return groupMssqlIndexRows(indexRows)
168
+ })
169
+ const indexes = []
169
170
 
170
- indexes.push(index)
171
- }
171
+ for (const indexData of groupedIndexRows) {
172
+ const index = new ColumnsIndex(this, indexData)
172
173
 
173
- return indexes
174
- })
174
+ indexes.push(index)
175
+ }
176
+
177
+ return indexes
175
178
  }
176
179
 
177
180
  /**
@@ -2,7 +2,6 @@
2
2
 
3
3
  import AlterTable from "./sql/alter-table.js"
4
4
  import Base from "../base.js"
5
- import Column from "./column.js"
6
5
  import CreateDatabase from "./sql/create-database.js"
7
6
  import CreateIndex from "./sql/create-index.js"
8
7
  import CreateTable from "./sql/create-table.js"
@@ -779,18 +778,26 @@ export default class VelociousDatabaseDriversMysql extends Base{
779
778
  * @returns {Promise<Array<import("../base-table.js").default>>} - Resolves with the tables.
780
779
  */
781
780
  async getTables() {
782
- return await this._cachedSchemaMetadata("tables", async () => {
783
- const result = await this.query("SHOW FULL TABLES")
784
- const tables = []
781
+ const tableRows = await this._cachedSchemaMetadata("tables", async () => await this.query("SHOW FULL TABLES"))
782
+ const tables = []
785
783
 
786
- for (const row of result) {
787
- const table = new Table(this, /** @type {Record<string, string>} */ (row))
784
+ for (const row of tableRows) {
785
+ const table = new Table(this, /** @type {Record<string, string>} */ (row))
788
786
 
789
- tables.push(table)
790
- }
787
+ tables.push(table)
788
+ }
791
789
 
792
- return tables
793
- })
790
+ return tables
791
+ }
792
+
793
+ /**
794
+ * Lists database names visible to this server connection (`SHOW DATABASES`).
795
+ * @returns {Promise<string[]>} - Resolves with the database names.
796
+ */
797
+ async listDatabases() {
798
+ const result = await this.query("SHOW DATABASES")
799
+
800
+ return result.map((row) => String(Object.values(row)[0]))
794
801
  }
795
802
 
796
803
  /**
@@ -803,13 +810,13 @@ export default class VelociousDatabaseDriversMysql extends Base{
803
810
  * Verified column-for-column against `SHOW FULL COLUMNS` on a 44-table MariaDB
804
811
  * schema; the only divergence was that sentinel.
805
812
  * @param {Array<import("../base-table.js").default>} tables - Tables to load columns for.
806
- * @returns {Promise<Map<string, Array<import("../base-column.js").default>>>} - Columns keyed by table name.
813
+ * @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>>} - Raw column rows keyed by table name.
807
814
  */
808
815
  async batchTableColumns(tables) {
809
- /** @type {Map<string, Array<import("../base-column.js").default>>} */
810
- const columnsByTable = new Map()
816
+ /** @type {Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>} */
817
+ const rowsByTable = new Map()
811
818
 
812
- if (tables.length === 0) return columnsByTable
819
+ if (tables.length === 0) return rowsByTable
813
820
 
814
821
  const tablesByName = new Map(tables.map((table) => [table.getName(), table]))
815
822
  const tableNamesSql = [...tablesByName.keys()].map((tableName) => this.quote(tableName)).join(", ")
@@ -836,13 +843,13 @@ export default class VelociousDatabaseDriversMysql extends Base{
836
843
 
837
844
  row.Default = normalizeInformationSchemaDefault(row.Default)
838
845
 
839
- const columns = columnsByTable.get(tableName) || []
846
+ const tableRows = rowsByTable.get(tableName) || []
840
847
 
841
- columns.push(new Column(table, /** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row)))
842
- columnsByTable.set(tableName, columns)
848
+ tableRows.push(/** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row))
849
+ rowsByTable.set(tableName, tableRows)
843
850
  }
844
851
 
845
- return columnsByTable
852
+ return rowsByTable
846
853
  }
847
854
 
848
855
  /**
@@ -18,22 +18,22 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
18
18
  }
19
19
 
20
20
  async getColumns() {
21
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
22
- const result = await this.driver.query(`SHOW FULL COLUMNS FROM \`${this.getName()}\``)
23
- const columns = []
21
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
22
+ return await this.driver.query(`SHOW FULL COLUMNS FROM \`${this.getName()}\``)
23
+ })
24
+ const columns = []
24
25
 
25
- for (const data of result) {
26
- const column = new Column(this, data)
26
+ for (const data of columnRows) {
27
+ const column = new Column(this, data)
27
28
 
28
- columns.push(column)
29
- }
29
+ columns.push(column)
30
+ }
30
31
 
31
- return columns
32
- })
32
+ return columns
33
33
  }
34
34
 
35
35
  async getForeignKeys() {
36
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
36
+ const foreignKeyRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
37
37
  const sql = `
38
38
  SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
39
39
  FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
@@ -42,21 +42,21 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
42
42
  TABLE_NAME = ${this.driver.quote(this.getName())}
43
43
  `
44
44
 
45
- const foreignKeyRows = await this.driver.query(sql)
46
- const foreignKeys = []
45
+ return await this.driver.query(sql)
46
+ })
47
+ const foreignKeys = []
47
48
 
48
- for (const foreignKeyRow of foreignKeyRows) {
49
- const foreignKey = new ForeignKey(foreignKeyRow)
49
+ for (const foreignKeyRow of foreignKeyRows) {
50
+ const foreignKey = new ForeignKey(foreignKeyRow)
50
51
 
51
- foreignKeys.push(foreignKey)
52
- }
52
+ foreignKeys.push(foreignKey)
53
+ }
53
54
 
54
- return foreignKeys
55
- })
55
+ return foreignKeys
56
56
  }
57
57
 
58
58
  async getIndexes() {
59
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
59
+ const groupedIndexRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
60
60
  const options = this.getOptions()
61
61
  const sql = `
62
62
  SELECT
@@ -76,7 +76,7 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
76
76
  SEQ_IN_INDEX
77
77
  `
78
78
  const indexesRows = await this.getDriver().query(sql)
79
- const indexes = []
79
+ const groupedRows = []
80
80
  const indexRowsByName = new Map()
81
81
 
82
82
  for (const indexRow of indexesRows) {
@@ -100,15 +100,23 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
100
100
  const groupedIndexRow = Object.assign({}, indexRow, {
101
101
  column_names: [indexRow.COLUMN_NAME]
102
102
  })
103
- const index = new ColumnsIndex(this, groupedIndexRow)
104
103
 
105
104
  indexRowsByName.set(indexRow.index_name, groupedIndexRow)
106
- indexes.push(index)
105
+ groupedRows.push(groupedIndexRow)
107
106
  }
108
107
  }
109
108
 
110
- return indexes
109
+ return groupedRows
111
110
  })
111
+ const indexes = []
112
+
113
+ for (const groupedIndexRow of groupedIndexRows) {
114
+ const index = new ColumnsIndex(this, groupedIndexRow)
115
+
116
+ indexes.push(index)
117
+ }
118
+
119
+ return indexes
112
120
  }
113
121
 
114
122
  /**
@@ -3,7 +3,6 @@
3
3
  import AlterTable from "./sql/alter-table.js"
4
4
  import wait from "awaitery/build/wait.js"
5
5
  import Base from "../base.js"
6
- import Column from "./column.js"
7
6
  import { Client, types as pgTypes } from "pg"
8
7
  import CreateDatabase from "./sql/create-database.js"
9
8
  import CreateIndex from "./sql/create-index.js"
@@ -335,31 +334,39 @@ export default class VelociousDatabaseDriversPgsql extends Base{
335
334
  * @returns {Promise<Array<import("../base-table.js").default>>} - Resolves with the tables.
336
335
  */
337
336
  async getTables() {
338
- return await this._cachedSchemaMetadata("tables", async () => {
339
- const result = await this.query("SELECT * FROM information_schema.tables WHERE table_catalog = CURRENT_DATABASE() AND table_schema = 'public'")
340
- const tables = []
337
+ const tableRows = await this._cachedSchemaMetadata("tables", async () => await this.query("SELECT * FROM information_schema.tables WHERE table_catalog = CURRENT_DATABASE() AND table_schema = 'public'"))
338
+ const tables = []
341
339
 
342
- for (const row of result) {
343
- const table = new Table(this, /** @type {Record<string, string>} */ (row))
340
+ for (const row of tableRows) {
341
+ const table = new Table(this, /** @type {Record<string, string>} */ (row))
344
342
 
345
- tables.push(table)
346
- }
343
+ tables.push(table)
344
+ }
345
+
346
+ return tables
347
+ }
348
+
349
+ /**
350
+ * Lists database names on this server connection from `pg_database`.
351
+ * @returns {Promise<string[]>} - Resolves with the database names.
352
+ */
353
+ async listDatabases() {
354
+ const result = await this.query("SELECT datname FROM pg_database ORDER BY datname")
347
355
 
348
- return tables
349
- })
356
+ return result.map((row) => String(row.datname))
350
357
  }
351
358
 
352
359
  /**
353
360
  * Reads column metadata for many tables in one query instead of one catalog
354
361
  * join per table.
355
362
  * @param {Array<import("../base-table.js").default>} tables - Tables to load columns for.
356
- * @returns {Promise<Map<string, Array<import("../base-column.js").default>>>} - Columns keyed by table name.
363
+ * @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>>} - Raw column rows keyed by table name.
357
364
  */
358
365
  async batchTableColumns(tables) {
359
- /** @type {Map<string, Array<import("../base-column.js").default>>} */
360
- const columnsByTable = new Map()
366
+ /** @type {Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>} */
367
+ const rowsByTable = new Map()
361
368
 
362
- if (tables.length === 0) return columnsByTable
369
+ if (tables.length === 0) return rowsByTable
363
370
 
364
371
  const tablesByName = new Map(tables.map((table) => [table.getName(), table]))
365
372
  const tableNamesSql = [...tablesByName.keys()].map((tableName) => this.quote(tableName)).join(", ")
@@ -396,13 +403,13 @@ export default class VelociousDatabaseDriversPgsql extends Base{
396
403
 
397
404
  if (!table) continue
398
405
 
399
- const columns = columnsByTable.get(tableName) || []
406
+ const tableRows = rowsByTable.get(tableName) || []
400
407
 
401
- columns.push(new Column(table, /** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row)))
402
- columnsByTable.set(tableName, columns)
408
+ tableRows.push(/** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row))
409
+ rowsByTable.set(tableName, tableRows)
403
410
  }
404
411
 
405
- return columnsByTable
412
+ return rowsByTable
406
413
  }
407
414
 
408
415
  /**
@@ -63,7 +63,7 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
63
63
  }
64
64
 
65
65
  async getColumns() {
66
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
66
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
67
67
  const result = await this.driver.query(`
68
68
  SELECT
69
69
  columns.*,
@@ -89,20 +89,21 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
89
89
  columns.table_schema = 'public' AND
90
90
  columns.table_name = '${this.getName()}'
91
91
  `)
92
- const columns = []
92
+ return result
93
+ })
94
+ const columns = []
93
95
 
94
- for (const data of result) {
95
- const column = new Column(this, data)
96
+ for (const data of columnRows) {
97
+ const column = new Column(this, data)
96
98
 
97
- columns.push(column)
98
- }
99
+ columns.push(column)
100
+ }
99
101
 
100
- return columns
101
- })
102
+ return columns
102
103
  }
103
104
 
104
105
  async getForeignKeys() {
105
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
106
+ const foreignKeyRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
106
107
  const sql = `
107
108
  SELECT
108
109
  tc.constraint_name,
@@ -126,21 +127,21 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
126
127
  tc.table_name = ${this.getDriver().quote(this.getName())}
127
128
  `
128
129
 
129
- const foreignKeyRows = await this.getDriver().query(sql)
130
- const foreignKeys = []
130
+ return await this.getDriver().query(sql)
131
+ })
132
+ const foreignKeys = []
131
133
 
132
- for (const foreignKeyRow of foreignKeyRows) {
133
- const foreignKey = new ForeignKey(foreignKeyRow)
134
+ for (const foreignKeyRow of foreignKeyRows) {
135
+ const foreignKey = new ForeignKey(foreignKeyRow)
134
136
 
135
- foreignKeys.push(foreignKey)
136
- }
137
+ foreignKeys.push(foreignKey)
138
+ }
137
139
 
138
- return foreignKeys
139
- })
140
+ return foreignKeys
140
141
  }
141
142
 
142
143
  async getIndexes() {
143
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
144
+ const groupedIndexRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
144
145
  const options = this.getOptions()
145
146
 
146
147
  const indexesRows = await this.getDriver().query(`
@@ -162,18 +163,19 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
162
163
  index_columns.ordinal_position
163
164
  `)
164
165
 
165
- const indexes = []
166
-
167
166
  const indexRows = indexesRows.map((indexRow) => normalizeIndexMetadataRow(indexRow))
168
167
 
169
- for (const indexData of groupPgsqlIndexRows(indexRows)) {
170
- const columnsIndex = new ColumnsIndex(this, indexData)
168
+ return groupPgsqlIndexRows(indexRows)
169
+ })
170
+ const indexes = []
171
171
 
172
- indexes.push(columnsIndex)
173
- }
172
+ for (const indexData of groupedIndexRows) {
173
+ const columnsIndex = new ColumnsIndex(this, indexData)
174
174
 
175
- return indexes
176
- })
175
+ indexes.push(columnsIndex)
176
+ }
177
+
178
+ return indexes
177
179
  }
178
180
 
179
181
  /**
@@ -132,18 +132,29 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
132
132
  * @returns {Promise<Array<import("../base-table.js").default>>} - Resolves with the tables.
133
133
  */
134
134
  async getTables() {
135
- return await this._cachedSchemaMetadata("tables", async () => {
136
- const result = await this.query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name")
137
- const tables = []
135
+ const tableRows = await this._cachedSchemaMetadata("tables", async () => await this.query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name"))
136
+ const tables = []
138
137
 
139
- for (const row of result) {
140
- const table = new Table({driver: this, row: /** @type {Record<string, string | number | null>} */ (row)})
138
+ for (const row of tableRows) {
139
+ const table = new Table({driver: this, row: /** @type {Record<string, string | number | null>} */ (row)})
141
140
 
142
- tables.push(table)
143
- }
141
+ tables.push(table)
142
+ }
144
143
 
145
- return tables
146
- })
144
+ return tables
145
+ }
146
+
147
+ /**
148
+ * SQLite has no server-side database catalog: the driver's own file is the
149
+ * only database it can list. `PRAGMA database_list` reports the attached
150
+ * schemas, so the listing stays driver-native instead of a raw-SQL caller
151
+ * convention.
152
+ * @returns {Promise<string[]>} - Resolves with the attached database names.
153
+ */
154
+ async listDatabases() {
155
+ const result = await this.query("PRAGMA database_list")
156
+
157
+ return result.map((row) => String(row.name))
147
158
  }
148
159
 
149
160
  /**
@@ -23,39 +23,39 @@ export default class VelociousDatabaseDriversSqliteTable extends BaseTable {
23
23
  * @returns {Promise<Array<import("../base-column.js").default>>} - Resolves with the columns.
24
24
  */
25
25
  async getColumns() {
26
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
27
- const result = await this.driver.query(`PRAGMA table_info('${this.getName()}')`)
28
- const columns = []
26
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
27
+ return await this.driver.query(`PRAGMA table_info('${this.getName()}')`)
28
+ })
29
+ const columns = []
29
30
 
30
- for (const columnData of result) {
31
- const column = new Column({column: columnData, driver: this.driver, table: this})
31
+ for (const columnData of columnRows) {
32
+ const column = new Column({column: columnData, driver: this.driver, table: this})
32
33
 
33
- columns.push(column)
34
- }
34
+ columns.push(column)
35
+ }
35
36
 
36
- return columns
37
- })
37
+ return columns
38
38
  }
39
39
 
40
40
  async getForeignKeys() {
41
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
42
- const foreignKeysData = await this.driver.query(`SELECT * FROM pragma_foreign_key_list(${this.driver.quote(this.getName())})`)
43
- const foreignKeys = []
41
+ const foreignKeysData = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
42
+ return await this.driver.query(`SELECT * FROM pragma_foreign_key_list(${this.driver.quote(this.getName())})`)
43
+ })
44
+ const foreignKeys = []
44
45
 
45
- for (const foreignKeyData of foreignKeysData) {
46
- const foreignKey = new ForeignKey(foreignKeyData, {tableName: this.getName()})
46
+ for (const foreignKeyData of foreignKeysData) {
47
+ const foreignKey = new ForeignKey(foreignKeyData, {tableName: this.getName()})
47
48
 
48
- foreignKeys.push(foreignKey)
49
- }
49
+ foreignKeys.push(foreignKey)
50
+ }
50
51
 
51
- return foreignKeys
52
- })
52
+ return foreignKeys
53
53
  }
54
54
 
55
55
  async getIndexes() {
56
- return await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
56
+ const indexDataRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "indexes", async () => {
57
57
  const rows = await this.getDriver().query(`PRAGMA index_list(${this.getOptions().quoteTableName(this.getName())})`)
58
- const indexes = []
58
+ const cachedIndexRows = []
59
59
 
60
60
  for (const row of rows) {
61
61
  const indexName = row.name
@@ -65,21 +65,27 @@ export default class VelociousDatabaseDriversSqliteTable extends BaseTable {
65
65
  continue
66
66
  }
67
67
 
68
- const columnsIndex = new ColumnsIndex(this, row)
69
- const indexMasterData = await this.getDriver().query(`SELECT * FROM sqlite_master WHERE type = 'index' AND name = ${this.getOptions().quote(columnsIndex.getName())}`)
68
+ const indexMasterData = await this.getDriver().query(`SELECT * FROM sqlite_master WHERE type = 'index' AND name = ${this.getOptions().quote(indexName)}`)
70
69
  const sql = indexMasterData[0]?.sql
71
70
 
72
- if (!sql) throw new Error(`Could not find SQL for index ${columnsIndex.getName()}`)
71
+ if (!sql) throw new Error(`Could not find SQL for index ${indexName}`)
73
72
 
74
- const indexData = /** @type {typeof columnsIndex.data & {columnNames?: string[]}} */ (columnsIndex.data)
73
+ const indexData = /** @type {Record<string, ReturnType<typeof JSON.parse>> & {columnNames?: string[]}} */ (row)
75
74
 
76
75
  indexData.columnNames = this._parseColumnsFromSQL(String(sql))
77
76
 
78
- indexes.push(columnsIndex)
77
+ cachedIndexRows.push(indexData)
79
78
  }
80
79
 
81
- return indexes
80
+ return cachedIndexRows
82
81
  })
82
+ const indexes = []
83
+
84
+ for (const cachedIndexData of indexDataRows) {
85
+ indexes.push(new ColumnsIndex(this, cachedIndexData))
86
+ }
87
+
88
+ return indexes
83
89
  }
84
90
 
85
91
  /**
@@ -1056,6 +1056,7 @@ export default class VelociousDatabasePoolAsyncTrackedMultiConnection extends Ba
1056
1056
  const DriverClass = databaseConfiguration.driver || this.driverClass
1057
1057
  if (!DriverClass) throw new Error("No driver class configured for frontend tenant SQLite deletion")
1058
1058
  await new DriverClass(databaseConfiguration, this.configuration).deleteDatabaseStorage()
1059
+ this.configuration.clearSchemaCachesForReuseKey(this.getConfigurationReuseKey(databaseConfiguration))
1059
1060
  }
1060
1061
 
1061
1062
  capturedConnectionInUse(/** @type {import("../../configuration-types.js").DatabaseConfigurationType} */ databaseConfiguration) {
@@ -270,11 +270,11 @@ class VelociousDatabasePoolBase {
270
270
  }
271
271
 
272
272
  /**
273
- * Runs get configuration reuse key.
274
- * @param {import("../../configuration-types.js").DatabaseConfigurationType} [databaseConfiguration] - Resolved configuration to identify.
275
- * @returns {string} - Reuse key for the currently resolved database configuration.
273
+ * Computes the physical-database reuse key for an explicit configuration, matching what a pool would stamp on its connections.
274
+ * @param {import("../../configuration-types.js").DatabaseConfigurationType} databaseConfiguration - Resolved configuration to identify.
275
+ * @returns {string} - Reuse key for the given database configuration.
276
276
  */
277
- getConfigurationReuseKey(databaseConfiguration = this.getConfiguration()) {
277
+ static configurationReuseKey(databaseConfiguration) {
278
278
  return stableStringify({
279
279
  database: databaseConfiguration.database,
280
280
  host: databaseConfiguration.host,
@@ -289,6 +289,15 @@ class VelociousDatabasePoolBase {
289
289
  })
290
290
  }
291
291
 
292
+ /**
293
+ * Runs get configuration reuse key.
294
+ * @param {import("../../configuration-types.js").DatabaseConfigurationType} [databaseConfiguration] - Resolved configuration to identify.
295
+ * @returns {string} - Reuse key for the currently resolved database configuration.
296
+ */
297
+ getConfigurationReuseKey(databaseConfiguration = this.getConfiguration()) {
298
+ return VelociousDatabasePoolBase.configurationReuseKey(databaseConfiguration)
299
+ }
300
+
292
301
  /**
293
302
  * Runs connection matches current configuration.
294
303
  * @param {import("../drivers/base.js").default} connection - Connection.
@@ -401,6 +410,7 @@ class VelociousDatabasePoolBase {
401
410
  this.clearSchemaCache()
402
411
  this.configuration.clearSchemaCachesForReuseKey(reuseKey)
403
412
  })
413
+ connection.setSchemaCacheMapProvider(() => this.configuration.schemaCacheMapForReuseKey(reuseKey))
404
414
  }
405
415
 
406
416
  /**
@@ -329,6 +329,7 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
329
329
  if (!DriverClass) throw new Error("No driver class configured for frontend tenant SQLite deletion")
330
330
  const driver = new DriverClass(databaseConfiguration, this.configuration)
331
331
  await driver.deleteDatabaseStorage()
332
+ this.configuration.clearSchemaCachesForReuseKey(this.getConfigurationReuseKey(databaseConfiguration))
332
333
  }
333
334
 
334
335
  capturedConnectionInUse(/** @type {import("../../configuration-types.js").DatabaseConfigurationType} */ databaseConfiguration) {