velocious 1.0.727 → 1.0.728
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/README.md +2 -2
- package/bin/velocious.js +2 -19
- package/build/application.js +32 -3
- package/build/background-jobs/main.js +9 -1
- package/build/background-jobs/worker.js +69 -6
- package/build/bin/velocious.js +2 -19
- package/build/cli/process-args.js +34 -0
- package/build/configuration.js +26 -0
- package/build/database/drivers/base.js +34 -12
- package/build/database/drivers/mssql/index.js +17 -18
- package/build/database/drivers/mssql/table.js +28 -25
- package/build/database/drivers/mysql/index.js +15 -18
- package/build/database/drivers/mysql/table.js +31 -23
- package/build/database/drivers/pgsql/index.js +15 -18
- package/build/database/drivers/pgsql/table.js +28 -26
- package/build/database/drivers/sqlite/base.js +7 -9
- package/build/database/drivers/sqlite/table.js +32 -26
- package/build/database/pool/async-tracked-multi-connection.js +1 -0
- package/build/database/pool/base.js +14 -4
- package/build/database/pool/single-multi-use.js +1 -0
- package/build/environment-handlers/node/cli/commands/server.js +1 -0
- package/build/http-server/server-lock.js +28 -4
- package/build/src/application.d.ts +7 -4
- package/build/src/application.d.ts.map +1 -1
- package/build/src/application.js +27 -4
- package/build/src/background-jobs/main.d.ts +2 -1
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +10 -2
- package/build/src/background-jobs/worker.d.ts +42 -0
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +61 -5
- package/build/src/cli/process-args.d.ts +11 -0
- package/build/src/cli/process-args.d.ts.map +1 -0
- package/build/src/cli/process-args.js +34 -0
- package/build/src/configuration.d.ts +13 -0
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +22 -1
- package/build/src/database/drivers/base.d.ts +15 -2
- package/build/src/database/drivers/base.d.ts.map +1 -1
- package/build/src/database/drivers/base.js +33 -13
- package/build/src/database/drivers/mssql/index.d.ts +2 -2
- package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mssql/index.js +17 -18
- package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
- package/build/src/database/drivers/mssql/table.js +25 -23
- package/build/src/database/drivers/mysql/index.d.ts +2 -2
- package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/index.js +16 -19
- package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/table.js +27 -22
- package/build/src/database/drivers/pgsql/index.d.ts +2 -2
- package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
- package/build/src/database/drivers/pgsql/index.js +16 -19
- package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
- package/build/src/database/drivers/pgsql/table.js +25 -23
- package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/base.js +8 -10
- package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/table.js +29 -25
- package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
- package/build/src/database/pool/async-tracked-multi-connection.js +2 -1
- package/build/src/database/pool/base.d.ts +6 -0
- package/build/src/database/pool/base.d.ts.map +1 -1
- package/build/src/database/pool/base.js +14 -5
- package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
- package/build/src/database/pool/single-multi-use.js +2 -1
- package/build/src/environment-handlers/node/cli/commands/server.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/server.js +2 -1
- package/build/src/http-server/server-lock.d.ts +23 -5
- package/build/src/http-server/server-lock.d.ts.map +1 -1
- package/build/src/http-server/server-lock.js +27 -5
- package/build/src/tenants/default-tenant-database-provisioning.d.ts.map +1 -1
- package/build/src/tenants/default-tenant-database-provisioning.js +7 -1
- package/build/tenants/default-tenant-database-provisioning.js +8 -0
- package/package.json +2 -2
- package/src/application.js +32 -3
- package/src/background-jobs/main.js +9 -1
- package/src/background-jobs/worker.js +69 -6
- package/src/cli/process-args.js +34 -0
- package/src/configuration.js +26 -0
- package/src/database/drivers/base.js +34 -12
- package/src/database/drivers/mssql/index.js +17 -18
- package/src/database/drivers/mssql/table.js +28 -25
- package/src/database/drivers/mysql/index.js +15 -18
- package/src/database/drivers/mysql/table.js +31 -23
- package/src/database/drivers/pgsql/index.js +15 -18
- package/src/database/drivers/pgsql/table.js +28 -26
- package/src/database/drivers/sqlite/base.js +7 -9
- package/src/database/drivers/sqlite/table.js +32 -26
- package/src/database/pool/async-tracked-multi-connection.js +1 -0
- package/src/database/pool/base.js +14 -4
- package/src/database/pool/single-multi-use.js +1 -0
- package/src/environment-handlers/node/cli/commands/server.js +1 -0
- package/src/http-server/server-lock.js +28 -4
- package/src/tenants/default-tenant-database-provisioning.js +8 -0
|
@@ -64,7 +64,7 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
async getColumns() {
|
|
67
|
-
|
|
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
|
-
|
|
89
|
+
return result
|
|
90
|
+
})
|
|
91
|
+
const columns = []
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
for (const data of columnRows) {
|
|
94
|
+
const column = new Column(this, data)
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
columns.push(column)
|
|
97
|
+
}
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
+
return columns
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
async getForeignKeys() {
|
|
102
|
-
|
|
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
|
-
|
|
129
|
-
|
|
129
|
+
return await this.driver.query(sql)
|
|
130
|
+
})
|
|
131
|
+
const foreignKeys = []
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
for (const foreignKeyRow of foreignKeyRows) {
|
|
134
|
+
const foreignKey = new ForeignKey(foreignKeyRow)
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
foreignKeys.push(foreignKey)
|
|
137
|
+
}
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
+
return foreignKeys
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
async getIndexes() {
|
|
142
|
-
|
|
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
|
-
|
|
168
|
-
|
|
167
|
+
return groupMssqlIndexRows(indexRows)
|
|
168
|
+
})
|
|
169
|
+
const indexes = []
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
for (const indexData of groupedIndexRows) {
|
|
172
|
+
const index = new ColumnsIndex(this, indexData)
|
|
172
173
|
|
|
173
|
-
|
|
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,16 @@ 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
|
-
|
|
783
|
-
|
|
784
|
-
const tables = []
|
|
781
|
+
const tableRows = await this._cachedSchemaMetadata("tables", async () => await this.query("SHOW FULL TABLES"))
|
|
782
|
+
const tables = []
|
|
785
783
|
|
|
786
|
-
|
|
787
|
-
|
|
784
|
+
for (const row of tableRows) {
|
|
785
|
+
const table = new Table(this, /** @type {Record<string, string>} */ (row))
|
|
788
786
|
|
|
789
|
-
|
|
790
|
-
|
|
787
|
+
tables.push(table)
|
|
788
|
+
}
|
|
791
789
|
|
|
792
|
-
|
|
793
|
-
})
|
|
790
|
+
return tables
|
|
794
791
|
}
|
|
795
792
|
|
|
796
793
|
/**
|
|
@@ -803,13 +800,13 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
803
800
|
* Verified column-for-column against `SHOW FULL COLUMNS` on a 44-table MariaDB
|
|
804
801
|
* schema; the only divergence was that sentinel.
|
|
805
802
|
* @param {Array<import("../base-table.js").default>} tables - Tables to load columns for.
|
|
806
|
-
* @returns {Promise<Map<string, Array<
|
|
803
|
+
* @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>>} - Raw column rows keyed by table name.
|
|
807
804
|
*/
|
|
808
805
|
async batchTableColumns(tables) {
|
|
809
|
-
/** @type {Map<string, Array<
|
|
810
|
-
const
|
|
806
|
+
/** @type {Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>} */
|
|
807
|
+
const rowsByTable = new Map()
|
|
811
808
|
|
|
812
|
-
if (tables.length === 0) return
|
|
809
|
+
if (tables.length === 0) return rowsByTable
|
|
813
810
|
|
|
814
811
|
const tablesByName = new Map(tables.map((table) => [table.getName(), table]))
|
|
815
812
|
const tableNamesSql = [...tablesByName.keys()].map((tableName) => this.quote(tableName)).join(", ")
|
|
@@ -836,13 +833,13 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
836
833
|
|
|
837
834
|
row.Default = normalizeInformationSchemaDefault(row.Default)
|
|
838
835
|
|
|
839
|
-
const
|
|
836
|
+
const tableRows = rowsByTable.get(tableName) || []
|
|
840
837
|
|
|
841
|
-
|
|
842
|
-
|
|
838
|
+
tableRows.push(/** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row))
|
|
839
|
+
rowsByTable.set(tableName, tableRows)
|
|
843
840
|
}
|
|
844
841
|
|
|
845
|
-
return
|
|
842
|
+
return rowsByTable
|
|
846
843
|
}
|
|
847
844
|
|
|
848
845
|
/**
|
|
@@ -18,22 +18,22 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async getColumns() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
26
|
+
for (const data of columnRows) {
|
|
27
|
+
const column = new Column(this, data)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
columns.push(column)
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
})
|
|
32
|
+
return columns
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async getForeignKeys() {
|
|
36
|
-
|
|
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
|
-
|
|
46
|
-
|
|
45
|
+
return await this.driver.query(sql)
|
|
46
|
+
})
|
|
47
|
+
const foreignKeys = []
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
for (const foreignKeyRow of foreignKeyRows) {
|
|
50
|
+
const foreignKey = new ForeignKey(foreignKeyRow)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
foreignKeys.push(foreignKey)
|
|
53
|
+
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
})
|
|
55
|
+
return foreignKeys
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async getIndexes() {
|
|
59
|
-
|
|
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
|
|
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
|
-
|
|
105
|
+
groupedRows.push(groupedIndexRow)
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
return
|
|
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,29 @@ 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
|
-
|
|
339
|
-
|
|
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
|
-
|
|
343
|
-
|
|
340
|
+
for (const row of tableRows) {
|
|
341
|
+
const table = new Table(this, /** @type {Record<string, string>} */ (row))
|
|
344
342
|
|
|
345
|
-
|
|
346
|
-
|
|
343
|
+
tables.push(table)
|
|
344
|
+
}
|
|
347
345
|
|
|
348
|
-
|
|
349
|
-
})
|
|
346
|
+
return tables
|
|
350
347
|
}
|
|
351
348
|
|
|
352
349
|
/**
|
|
353
350
|
* Reads column metadata for many tables in one query instead of one catalog
|
|
354
351
|
* join per table.
|
|
355
352
|
* @param {Array<import("../base-table.js").default>} tables - Tables to load columns for.
|
|
356
|
-
* @returns {Promise<Map<string, Array<
|
|
353
|
+
* @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>>} - Raw column rows keyed by table name.
|
|
357
354
|
*/
|
|
358
355
|
async batchTableColumns(tables) {
|
|
359
|
-
/** @type {Map<string, Array<
|
|
360
|
-
const
|
|
356
|
+
/** @type {Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>} */
|
|
357
|
+
const rowsByTable = new Map()
|
|
361
358
|
|
|
362
|
-
if (tables.length === 0) return
|
|
359
|
+
if (tables.length === 0) return rowsByTable
|
|
363
360
|
|
|
364
361
|
const tablesByName = new Map(tables.map((table) => [table.getName(), table]))
|
|
365
362
|
const tableNamesSql = [...tablesByName.keys()].map((tableName) => this.quote(tableName)).join(", ")
|
|
@@ -396,13 +393,13 @@ export default class VelociousDatabaseDriversPgsql extends Base{
|
|
|
396
393
|
|
|
397
394
|
if (!table) continue
|
|
398
395
|
|
|
399
|
-
const
|
|
396
|
+
const tableRows = rowsByTable.get(tableName) || []
|
|
400
397
|
|
|
401
|
-
|
|
402
|
-
|
|
398
|
+
tableRows.push(/** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row))
|
|
399
|
+
rowsByTable.set(tableName, tableRows)
|
|
403
400
|
}
|
|
404
401
|
|
|
405
|
-
return
|
|
402
|
+
return rowsByTable
|
|
406
403
|
}
|
|
407
404
|
|
|
408
405
|
/**
|
|
@@ -63,7 +63,7 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
async getColumns() {
|
|
66
|
-
|
|
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
|
-
|
|
92
|
+
return result
|
|
93
|
+
})
|
|
94
|
+
const columns = []
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
for (const data of columnRows) {
|
|
97
|
+
const column = new Column(this, data)
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
columns.push(column)
|
|
100
|
+
}
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
})
|
|
102
|
+
return columns
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
async getForeignKeys() {
|
|
105
|
-
|
|
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
|
-
|
|
130
|
-
|
|
130
|
+
return await this.getDriver().query(sql)
|
|
131
|
+
})
|
|
132
|
+
const foreignKeys = []
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
for (const foreignKeyRow of foreignKeyRows) {
|
|
135
|
+
const foreignKey = new ForeignKey(foreignKeyRow)
|
|
134
136
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
foreignKeys.push(foreignKey)
|
|
138
|
+
}
|
|
137
139
|
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
+
return foreignKeys
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
async getIndexes() {
|
|
143
|
-
|
|
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
|
-
|
|
170
|
-
|
|
168
|
+
return groupPgsqlIndexRows(indexRows)
|
|
169
|
+
})
|
|
170
|
+
const indexes = []
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
for (const indexData of groupedIndexRows) {
|
|
173
|
+
const columnsIndex = new ColumnsIndex(this, indexData)
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
}
|
|
175
|
+
indexes.push(columnsIndex)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return indexes
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
/**
|
|
@@ -132,18 +132,16 @@ 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
|
-
|
|
136
|
-
|
|
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
|
-
|
|
140
|
-
|
|
138
|
+
for (const row of tableRows) {
|
|
139
|
+
const table = new Table({driver: this, row: /** @type {Record<string, string | number | null>} */ (row)})
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
tables.push(table)
|
|
142
|
+
}
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
})
|
|
144
|
+
return tables
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
/**
|
|
@@ -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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
31
|
+
for (const columnData of columnRows) {
|
|
32
|
+
const column = new Column({column: columnData, driver: this.driver, table: this})
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
columns.push(column)
|
|
35
|
+
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
})
|
|
37
|
+
return columns
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
async getForeignKeys() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
46
|
+
for (const foreignKeyData of foreignKeysData) {
|
|
47
|
+
const foreignKey = new ForeignKey(foreignKeyData, {tableName: this.getName()})
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
foreignKeys.push(foreignKey)
|
|
50
|
+
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
})
|
|
52
|
+
return foreignKeys
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
async getIndexes() {
|
|
56
|
-
|
|
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
|
|
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
|
|
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 ${
|
|
71
|
+
if (!sql) throw new Error(`Could not find SQL for index ${indexName}`)
|
|
73
72
|
|
|
74
|
-
const indexData = /** @type {typeof
|
|
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
|
-
|
|
77
|
+
cachedIndexRows.push(indexData)
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
return
|
|
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
|
-
*
|
|
274
|
-
* @param {import("../../configuration-types.js").DatabaseConfigurationType}
|
|
275
|
-
* @returns {string} - Reuse key for the
|
|
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
|
-
|
|
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) {
|
|
@@ -145,6 +145,7 @@ export default class VelociousCliCommandsServer extends BaseCommand{
|
|
|
145
145
|
const application = new Application({
|
|
146
146
|
configuration,
|
|
147
147
|
httpServer,
|
|
148
|
+
httpServerLockOptOut: parsedProcessArgs["no-server-lock"] === true,
|
|
148
149
|
type: "server"
|
|
149
150
|
})
|
|
150
151
|
const environment = configuration.getEnvironment()
|