velocious 1.0.43 → 1.0.45
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/package.json +1 -1
- package/src/database/drivers/mssql/index.js +9 -2
- package/src/database/drivers/mysql/index.js +6 -0
- package/src/database/drivers/pgsql/index.js +6 -0
- package/src/database/drivers/sqlite/base.js +4 -0
- package/src/database/migration/index.js +5 -1
- package/src/database/table-data/index.js +1 -0
- package/src/http-server/client/request-runner.js +2 -1
- package/src/testing/test-runner.js +4 -1
- package/src/utils/backtrace-cleaner.js +15 -0
package/package.json
CHANGED
|
@@ -20,7 +20,8 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
20
20
|
const sqlConfig = digg(args, "sqlConfig")
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
this.connection =
|
|
23
|
+
this.connection = new mssql.ConnectionPool(sqlConfig)
|
|
24
|
+
await this.connection.connect()
|
|
24
25
|
} catch (error) {
|
|
25
26
|
throw new Error(`Couldn't connect to database: ${error.message}`) // Re-throw to fix unuseable stack trace.
|
|
26
27
|
}
|
|
@@ -52,6 +53,12 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
52
53
|
return createTable.toSql()
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
async currentDatabase() {
|
|
57
|
+
const rows = await this.query("SELECT DB_NAME() AS db_name")
|
|
58
|
+
|
|
59
|
+
return digg(rows, 0, "db_name")
|
|
60
|
+
}
|
|
61
|
+
|
|
55
62
|
async disableForeignKeys() {
|
|
56
63
|
await this.query("EXEC sp_MSforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\"")
|
|
57
64
|
}
|
|
@@ -76,7 +83,7 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
76
83
|
if (this._currentTransaction) {
|
|
77
84
|
request = new mssql.Request(this._currentTransaction)
|
|
78
85
|
} else {
|
|
79
|
-
request = mssql
|
|
86
|
+
request = new mssql.Request(this.connection)
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
while (true) {
|
|
@@ -62,6 +62,12 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
62
62
|
return createTable.toSql()
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
async currentDatabase() {
|
|
66
|
+
const rows = await this.query("SELECT DATABASE() AS db_name")
|
|
67
|
+
|
|
68
|
+
return digg(rows, 0, "db_name")
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
async disableForeignKeys() {
|
|
66
72
|
await this.query("SET FOREIGN_KEY_CHECKS = 0")
|
|
67
73
|
}
|
|
@@ -70,6 +70,12 @@ export default class VelociousDatabaseDriversPgsql extends Base{
|
|
|
70
70
|
return createTable.toSql()
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
async currentDatabase() {
|
|
74
|
+
const rows = await this.query("SELECT CURRENT_DATABASE() AS db_name")
|
|
75
|
+
|
|
76
|
+
return digg(rows, 0, "db_name")
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
async disableForeignKeys() {
|
|
74
80
|
await this.query("SET session_replication_role = 'replica'")
|
|
75
81
|
}
|
|
@@ -26,6 +26,8 @@ export default class VelociousDatabaseMigration {
|
|
|
26
26
|
return this._databaseIdentifier
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
getDriver() { return this._db }
|
|
30
|
+
|
|
29
31
|
async addColumn(tableName, columnName, columnType, args) {
|
|
30
32
|
const tableColumnArgs = Object.assign({type: columnType}, args)
|
|
31
33
|
|
|
@@ -101,7 +103,9 @@ export default class VelociousDatabaseMigration {
|
|
|
101
103
|
|
|
102
104
|
if (!(idType in tableData)) throw new Error(`Unsupported primary key type: ${idType}`)
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
if (id !== false) {
|
|
107
|
+
tableData[idType]("id", {autoIncrement: true, default: idDefault, null: false, primaryKey: true})
|
|
108
|
+
}
|
|
105
109
|
|
|
106
110
|
if (callback) {
|
|
107
111
|
callback(tableData)
|
|
@@ -76,6 +76,7 @@ export default class TableData {
|
|
|
76
76
|
boolean = (name, args) => this._defineColumn(name, Object.assign({type: "boolean"}, args))
|
|
77
77
|
datetime = (name, args) => this._defineColumn(name, Object.assign({type: "datetime"}, args))
|
|
78
78
|
integer = (name, args = {}) => this._defineColumn(name, Object.assign({type: "integer"}, args))
|
|
79
|
+
tinyint = (name, args = {}) => this._defineColumn(name, Object.assign({type: "tinyint"}, args))
|
|
79
80
|
|
|
80
81
|
references(name, args = {}) {
|
|
81
82
|
const columnName = `${name}_id`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BacktraceCleaner from "../../utils/backtrace-cleaner.js"
|
|
1
2
|
import EventEmitter from "events"
|
|
2
3
|
import {Logger} from "../../logger.js"
|
|
3
4
|
import Response from "./response.js"
|
|
@@ -40,7 +41,7 @@ export default class VelociousHttpServerClientRequestRunner {
|
|
|
40
41
|
await routesResolver.resolve()
|
|
41
42
|
}
|
|
42
43
|
} catch (error) {
|
|
43
|
-
await this.logger.error(() => [`Error while running request: ${
|
|
44
|
+
await this.logger.error(() => [`Error while running request: ${BacktraceCleaner.getCleanedStack(error)}`])
|
|
44
45
|
|
|
45
46
|
response.setStatus(500)
|
|
46
47
|
response.setErrorBody(error)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {addTrackedStackToError} from "../utils/with-tracked-stack.js"
|
|
2
2
|
import Application from "../../src/application.js"
|
|
3
|
+
import BacktraceCleaner from "../utils/backtrace-cleaner.js"
|
|
3
4
|
import RequestClient from "./request-client.js"
|
|
4
5
|
import {tests} from "./test.js"
|
|
5
6
|
|
|
@@ -147,7 +148,9 @@ export default class TestRunner {
|
|
|
147
148
|
// console.error(`${leftPadding} Test failed: ${error.message}`)
|
|
148
149
|
addTrackedStackToError(error)
|
|
149
150
|
|
|
150
|
-
const
|
|
151
|
+
const backtraceCleaner = new BacktraceCleaner(error)
|
|
152
|
+
const cleanedStack = backtraceCleaner.getCleanedStack()
|
|
153
|
+
const stackLines = cleanedStack.split("\n")
|
|
151
154
|
|
|
152
155
|
for (const stackLine of stackLines) {
|
|
153
156
|
console.error(`${leftPadding} ${stackLine}`)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default class BacktraceCleaner {
|
|
2
|
+
static getCleanedStack(error) {
|
|
3
|
+
return new BacktraceCleaner(error).getCleanedStack()
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor(error) {
|
|
7
|
+
this.error = error
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getCleanedStack() {
|
|
11
|
+
const backtrace = this.error.stack.split("\n")
|
|
12
|
+
|
|
13
|
+
return backtrace.filter((line) => !line.includes("node_modules") && !line.includes("(node:internal/process/")).join("\n")
|
|
14
|
+
}
|
|
15
|
+
}
|