velocious 1.0.44 → 1.0.46
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 +2 -3
- package/src/cli/base-command.js +2 -1
- package/src/cli/commands/test.js +2 -0
- package/src/cli/index.js +1 -1
- package/src/configuration.js +2 -3
- 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/record/index.js +14 -3
- package/src/database/table-data/index.js +1 -0
- package/src/http-server/worker-handler/index.js +1 -0
- package/src/http-server/worker-handler/worker-thread.js +3 -2
- package/spec/support/jasmine.json +0 -12
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"velocious": "bin/velocious.js"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.46",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
|
|
10
10
|
"velocious": "asd"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"description": "",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"awaitery": "^1.0.1",
|
|
26
|
-
"jasmine": "^5.0.2",
|
|
27
26
|
"mssql": "^11.0.1",
|
|
28
27
|
"mysql": "^2.18.1",
|
|
29
28
|
"node-fetch": "^3.3.1",
|
package/src/cli/base-command.js
CHANGED
|
@@ -7,5 +7,6 @@ export default class VelociousCliBaseCommand {
|
|
|
7
7
|
this.processArgs = args.processArgs
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
directory
|
|
10
|
+
directory() { return digg(this, "configuration").getDirectory() }
|
|
11
|
+
getConfiguration() { return this.configuration }
|
|
11
12
|
}
|
package/src/cli/commands/test.js
CHANGED
|
@@ -4,6 +4,8 @@ import TestRunner from "../../testing/test-runner.js"
|
|
|
4
4
|
|
|
5
5
|
export default class VelociousCliCommandsTest extends BaseCommand {
|
|
6
6
|
async execute() {
|
|
7
|
+
this.getConfiguration().setEnvironment("test")
|
|
8
|
+
|
|
7
9
|
const directory = process.env.VELOCIOUS_TEST_DIR || this.directory()
|
|
8
10
|
const testFilesFinder = new TestFilesFinder({directory, processArgs: this.processArgs})
|
|
9
11
|
const testFiles = await testFilesFinder.findTestFiles()
|
package/src/cli/index.js
CHANGED
package/src/configuration.js
CHANGED
|
@@ -78,11 +78,10 @@ export default class VelociousConfiguration {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
getEnvironment() { return digg(this, "_environment") }
|
|
81
|
+
setEnvironment(newEnvironment) { this._environment = newEnvironment }
|
|
81
82
|
|
|
82
83
|
getLocaleFallbacks = () => this.localeFallbacks
|
|
83
|
-
setLocaleFallbacks(newLocaleFallbacks) {
|
|
84
|
-
this.localeFallbacks = newLocaleFallbacks
|
|
85
|
-
}
|
|
84
|
+
setLocaleFallbacks(newLocaleFallbacks) { this.localeFallbacks = newLocaleFallbacks }
|
|
86
85
|
|
|
87
86
|
getLocale() {
|
|
88
87
|
if (typeof this.locale == "function") {
|
|
@@ -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)
|
|
@@ -204,6 +204,8 @@ class VelociousDatabaseRecord {
|
|
|
204
204
|
this._table = await this.connection().getTableByName(this.tableName())
|
|
205
205
|
this._columns = await this._getTable().getColumns()
|
|
206
206
|
this._columnsAsHash = {}
|
|
207
|
+
this._columnNameToAttributeName = {}
|
|
208
|
+
this._attributeNameToColumnName = {}
|
|
207
209
|
|
|
208
210
|
for (const column of this._columns) {
|
|
209
211
|
this._columnsAsHash[column.getName()] = column
|
|
@@ -212,6 +214,9 @@ class VelociousDatabaseRecord {
|
|
|
212
214
|
const camelizedColumnNameBigFirst = inflection.camelize(column.getName())
|
|
213
215
|
const setterMethodName = `set${camelizedColumnNameBigFirst}`
|
|
214
216
|
|
|
217
|
+
this._attributeNameToColumnName[camelizedColumnName] = column.getName()
|
|
218
|
+
this._columnNameToAttributeName[column.getName()] = camelizedColumnName
|
|
219
|
+
|
|
215
220
|
this.prototype[camelizedColumnName] = function () {
|
|
216
221
|
return this.readAttribute(camelizedColumnName)
|
|
217
222
|
}
|
|
@@ -300,7 +305,11 @@ class VelociousDatabaseRecord {
|
|
|
300
305
|
}
|
|
301
306
|
|
|
302
307
|
_setColumnAttribute(name, newValue) {
|
|
303
|
-
|
|
308
|
+
if (!this.constructor._attributeNameToColumnName) throw new Error("No attribute-to-column mapping. Has record been initialized?")
|
|
309
|
+
|
|
310
|
+
const columnName = this.constructor._attributeNameToColumnName[name]
|
|
311
|
+
|
|
312
|
+
if (!columnName) throw new Error(`Couldn't figure out column name for attribute: ${attributeName}`)
|
|
304
313
|
|
|
305
314
|
if (this._attributes[columnName] != newValue) {
|
|
306
315
|
this._changes[columnName] = newValue
|
|
@@ -767,9 +776,11 @@ class VelociousDatabaseRecord {
|
|
|
767
776
|
}
|
|
768
777
|
|
|
769
778
|
readAttribute(attributeName) {
|
|
770
|
-
const
|
|
779
|
+
const columnName = this.constructor._attributeNameToColumnName[attributeName]
|
|
780
|
+
|
|
781
|
+
if (!columnName) throw new Error(`Couldn't figure out column name for attribute: ${attributeName}`)
|
|
771
782
|
|
|
772
|
-
return this.readColumn(
|
|
783
|
+
return this.readColumn(columnName)
|
|
773
784
|
}
|
|
774
785
|
|
|
775
786
|
readColumn(attributeName) {
|
|
@@ -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`
|
|
@@ -25,11 +25,12 @@ export default class VelociousHttpServerWorkerHandlerWorkerThread {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async initialize() {
|
|
28
|
-
const {debug, directory} = digs(this.workerData, "debug", "directory")
|
|
29
|
-
const configurationPath = `${
|
|
28
|
+
const {debug, directory, environment} = digs(this.workerData, "debug", "directory", "environment")
|
|
29
|
+
const configurationPath = `${directory}/src/config/configuration.js`
|
|
30
30
|
const configurationImport = await import(configurationPath)
|
|
31
31
|
|
|
32
32
|
this.configuration = configurationImport.default
|
|
33
|
+
this.configuration.setEnvironment(environment)
|
|
33
34
|
this.configuration.setCurrent()
|
|
34
35
|
|
|
35
36
|
this.application = new Application({configuration: this.configuration, debug, directory})
|