velocious 1.0.104 → 1.0.106
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/spec/dummy/dummy-directory.js +2 -0
- package/spec/dummy/index.js +5 -1
- package/src/application.js +1 -0
- package/src/configuration-types.js +6 -0
- package/src/controller.js +44 -24
- package/src/database/drivers/base-foreign-key.js +1 -1
- package/src/database/drivers/base.js +2 -2
- package/src/database/drivers/mssql/column.js +6 -0
- package/src/database/drivers/mssql/columns-index.js +2 -5
- package/src/database/drivers/mssql/foreign-key.js +2 -0
- package/src/database/drivers/mssql/options.js +25 -0
- package/src/database/drivers/mssql/query-parser.js +2 -0
- package/src/database/drivers/mysql/options.js +9 -0
- package/src/database/drivers/mysql/sql/alter-table.js +2 -0
- package/src/database/drivers/mysql/sql/create-database.js +2 -0
- package/src/database/drivers/mysql/sql/create-index.js +2 -0
- package/src/database/drivers/mysql/sql/create-table.js +2 -0
- package/src/database/drivers/mysql/sql/delete.js +2 -0
- package/src/database/drivers/mysql/sql/drop-table.js +2 -0
- package/src/database/drivers/mysql/sql/insert.js +2 -0
- package/src/database/drivers/mysql/sql/update.js +2 -0
- package/src/database/drivers/pgsql/column.js +6 -0
- package/src/database/drivers/pgsql/columns-index.js +2 -0
- package/src/database/drivers/pgsql/foreign-key.js +2 -0
- package/src/database/drivers/pgsql/options.js +9 -0
- package/src/database/drivers/pgsql/query-parser.js +2 -0
- package/src/database/drivers/pgsql/sql/alter-table.js +2 -0
- package/src/database/drivers/pgsql/sql/create-database.js +5 -4
- package/src/database/drivers/pgsql/sql/create-index.js +2 -0
- package/src/database/drivers/pgsql/sql/create-table.js +2 -0
- package/src/database/drivers/pgsql/sql/delete.js +2 -0
- package/src/database/drivers/pgsql/sql/drop-table.js +2 -0
- package/src/database/drivers/pgsql/sql/insert.js +2 -0
- package/src/database/drivers/pgsql/sql/update.js +2 -0
- package/src/database/drivers/pgsql/table.js +6 -0
- package/src/database/drivers/sqlite/columns-index.js +2 -6
- package/src/database/drivers/sqlite/connection-remote.js +7 -0
- package/src/database/drivers/sqlite/connection-sql-js.js +12 -2
- package/src/database/drivers/sqlite/foreign-key.js +7 -0
- package/src/database/drivers/sqlite/index.js +7 -1
- package/src/database/drivers/sqlite/index.web.js +12 -3
- package/src/database/drivers/sqlite/options.js +9 -0
- package/src/database/drivers/sqlite/query-parser.js +2 -0
- package/src/database/drivers/sqlite/query.js +19 -6
- package/src/database/drivers/sqlite/query.web.js +13 -1
- package/src/database/initializer-from-require-context.js +11 -1
- package/src/database/migrator/types.js +2 -0
- package/src/database/pool/base-methods-forward.js +7 -0
- package/src/database/query/delete-base.js +8 -0
- package/src/database/query/preloader/belongs-to.js +16 -1
- package/src/database/query/preloader/has-many.js +19 -1
- package/src/database/query/preloader/has-one.js +20 -2
- package/src/database/query/preloader.js +19 -4
- package/src/database/query/update-base.js +9 -0
- package/src/database/query-parser/limit-parser.js +7 -2
- package/src/database/query-parser/options.js +47 -6
- package/src/database/query-parser/order-parser.js +11 -6
- package/src/database/query-parser/select-parser.js +8 -5
- package/src/database/query-parser/where-parser.js +11 -5
- package/src/database/record/index.js +1 -4
- package/src/database/record/instance-relationships/base.js +10 -1
- package/src/database/record/record-not-found-error.js +2 -0
- package/src/database/record/user-module.js +13 -0
- package/src/database/record/validators/uniqueness.js +13 -2
- package/src/error-logger.js +17 -3
- package/src/http-client/index.js +34 -2
- package/src/http-client/request.js +1 -1
- package/src/http-server/client/params-to-object.js +28 -0
- package/src/initializer.js +2 -0
- package/src/routes/app-routes.js +3 -1
- package/src/routes/base-route.js +67 -58
- package/src/routes/basic-route.js +76 -0
- package/src/routes/get-route.js +21 -5
- package/src/routes/index.js +10 -0
- package/src/routes/namespace-route.js +21 -5
- package/src/routes/post-route.js +20 -5
- package/src/routes/resolver.js +15 -2
- package/src/routes/resource-route.js +21 -5
- package/src/routes/root-route.js +3 -3
- package/src/testing/request-client.js +19 -14
- package/src/testing/test-runner.js +16 -10
- package/src/testing/test.js +71 -23
- package/src/utils/with-tracked-stack-async-hooks.js +22 -4
- package/src/utils/with-tracked-stack.js +9 -0
package/package.json
CHANGED
package/spec/dummy/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import Application from "../../src/application.js"
|
|
2
4
|
import {digg} from "diggerize"
|
|
3
5
|
import dummyConfiguration from "./src/config/configuration.js"
|
|
@@ -36,10 +38,12 @@ export default class Dummy {
|
|
|
36
38
|
await migrator.migrateFiles(await environmentHandlerNode.findMigrations(), digg(environmentHandlerNode, "requireMigration"))
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/** @param {function(): Promise<any>} callback */
|
|
39
42
|
static async run(callback) {
|
|
40
43
|
await this.current().run(callback)
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/** @param {function(): Promise<void>} callback */
|
|
43
47
|
async run(callback) {
|
|
44
48
|
await dummyConfiguration.ensureConnections(async () => {
|
|
45
49
|
await Dummy.prepare()
|
|
@@ -72,7 +76,7 @@ export default class Dummy {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
async stop() {
|
|
75
|
-
if (this.application
|
|
79
|
+
if (this.application?.isActive()) {
|
|
76
80
|
await this.application.stop()
|
|
77
81
|
}
|
|
78
82
|
}
|
package/src/application.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @module types
|
|
3
5
|
*/
|
|
@@ -18,11 +20,15 @@
|
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* @typedef {object} DatabaseConfigurationType
|
|
23
|
+
* @property {function() : void} [getConnection]
|
|
21
24
|
* @property {string} [host]
|
|
22
25
|
* @property {boolean} [migrations]
|
|
23
26
|
* @property {string} [password]
|
|
27
|
+
* @property {number} [port]
|
|
28
|
+
* @property {string} [name]
|
|
24
29
|
* @property {object} [record]
|
|
25
30
|
* @property {boolean} [record.transactions]
|
|
31
|
+
* @property {boolean} [reset]
|
|
26
32
|
* @property {string} [username]
|
|
27
33
|
*/
|
|
28
34
|
|
package/src/controller.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
2
3
|
import ejs from "ejs"
|
|
3
4
|
import {incorporate} from "incorporator"
|
|
4
5
|
import * as inflection from "inflection"
|
|
@@ -11,11 +12,24 @@ export default class VelociousController {
|
|
|
11
12
|
* @returns {void}
|
|
12
13
|
*/
|
|
13
14
|
static beforeAction(methodName) {
|
|
14
|
-
if (!this._beforeActions)
|
|
15
|
+
if (!this._beforeActions) {
|
|
16
|
+
/** @type {Array<string>} */
|
|
17
|
+
this._beforeActions = []
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
this._beforeActions.push(methodName)
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} args
|
|
25
|
+
* @param {string} args.action
|
|
26
|
+
* @param {import("./configuration.js").default} args.configuration
|
|
27
|
+
* @param {string} args.controller
|
|
28
|
+
* @param {object} args.params
|
|
29
|
+
* @param {import("./http-server/client/request.js").default} args.request
|
|
30
|
+
* @param {import("./http-server/client/response.js").default} args.response
|
|
31
|
+
* @param {string} args.viewPath
|
|
32
|
+
*/
|
|
19
33
|
constructor({action, configuration, controller, params, request, response, viewPath}) {
|
|
20
34
|
if (!action) throw new Error("No action given")
|
|
21
35
|
if (!configuration) throw new Error("No configuration given")
|
|
@@ -36,30 +50,32 @@ export default class VelociousController {
|
|
|
36
50
|
this._viewPath = viewPath
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
/**
|
|
40
|
-
* @returns {string}
|
|
41
|
-
*/
|
|
53
|
+
/** @returns {string} */
|
|
42
54
|
getAction() { return this._action }
|
|
43
55
|
|
|
44
|
-
/**
|
|
45
|
-
* @returns {import("./configuration.js").default}
|
|
46
|
-
*/
|
|
56
|
+
/** @returns {import("./configuration.js").default} */
|
|
47
57
|
getConfiguration() { return this._configuration }
|
|
48
58
|
|
|
49
|
-
/**
|
|
50
|
-
* @returns {object}
|
|
51
|
-
*/
|
|
59
|
+
/** @returns {object} */
|
|
52
60
|
getParams() { return this._params }
|
|
53
61
|
|
|
62
|
+
/** @returns {import("./http-server/client/request.js").default} */
|
|
63
|
+
getRequest() { return this._request }
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
|
-
* @
|
|
66
|
+
* @private
|
|
67
|
+
* @returns {typeof VelociousController}
|
|
56
68
|
*/
|
|
57
|
-
|
|
69
|
+
_getControllerClass() {
|
|
70
|
+
const controllerClass = /** @type {typeof VelociousController} */ (this.constructor)
|
|
71
|
+
|
|
72
|
+
return controllerClass
|
|
73
|
+
}
|
|
58
74
|
|
|
59
75
|
async _runBeforeCallbacks() {
|
|
60
76
|
await this.logger.debug("_runBeforeCallbacks")
|
|
61
77
|
|
|
62
|
-
let currentControllerClass = this.
|
|
78
|
+
let currentControllerClass = this._getControllerClass()
|
|
63
79
|
|
|
64
80
|
while (currentControllerClass) {
|
|
65
81
|
await this.logger.debug(`Running callbacks for ${currentControllerClass.name}`)
|
|
@@ -68,6 +84,7 @@ export default class VelociousController {
|
|
|
68
84
|
|
|
69
85
|
if (beforeActions) {
|
|
70
86
|
for (const beforeActionName of beforeActions) {
|
|
87
|
+
// @ts-expect-error
|
|
71
88
|
const beforeAction = currentControllerClass.prototype[beforeActionName]
|
|
72
89
|
|
|
73
90
|
if (!beforeAction) throw new Error(`No such before action: ${beforeActionName}`)
|
|
@@ -91,7 +108,13 @@ export default class VelociousController {
|
|
|
91
108
|
*/
|
|
92
109
|
params() { return this._params }
|
|
93
110
|
|
|
94
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @param {object} [args]
|
|
113
|
+
* @param {object} [args.json]
|
|
114
|
+
* @param {number} [args.status]
|
|
115
|
+
* @returns {Promise<void>}
|
|
116
|
+
*/
|
|
117
|
+
async render({json, status, ...restArgs} = {}) {
|
|
95
118
|
restArgsError(restArgs)
|
|
96
119
|
|
|
97
120
|
if (json) {
|
|
@@ -102,9 +125,10 @@ export default class VelociousController {
|
|
|
102
125
|
this._response.setStatus(status)
|
|
103
126
|
}
|
|
104
127
|
|
|
105
|
-
return this.renderView()
|
|
128
|
+
return await this.renderView()
|
|
106
129
|
}
|
|
107
130
|
|
|
131
|
+
/** @param {object} json */
|
|
108
132
|
renderJsonArg(json) {
|
|
109
133
|
const body = JSON.stringify(json)
|
|
110
134
|
|
|
@@ -115,7 +139,7 @@ export default class VelociousController {
|
|
|
115
139
|
renderView() {
|
|
116
140
|
return new Promise((resolve, reject) => {
|
|
117
141
|
const viewPath = `${this._viewPath}/${inflection.dasherize(inflection.underscore(this._action))}.ejs`
|
|
118
|
-
const {viewParams} =
|
|
142
|
+
const {viewParams} = this
|
|
119
143
|
const actualViewParams = incorporate({controller: this}, viewParams)
|
|
120
144
|
|
|
121
145
|
ejs.renderFile(viewPath, actualViewParams, {}, (err, str) => {
|
|
@@ -125,7 +149,7 @@ export default class VelociousController {
|
|
|
125
149
|
this._response.setHeader("Content-Type", "text/html; charset=UTF-8")
|
|
126
150
|
this._response.setBody(str)
|
|
127
151
|
|
|
128
|
-
resolve()
|
|
152
|
+
resolve(null)
|
|
129
153
|
}
|
|
130
154
|
})
|
|
131
155
|
})
|
|
@@ -135,13 +159,9 @@ export default class VelociousController {
|
|
|
135
159
|
throw new Error("renderText stub")
|
|
136
160
|
}
|
|
137
161
|
|
|
138
|
-
/**
|
|
139
|
-
* @returns {import("./http-server/client/request.js").default}
|
|
140
|
-
*/
|
|
162
|
+
/** @returns {import("./http-server/client/request.js").default} */
|
|
141
163
|
request() { return this._request }
|
|
142
164
|
|
|
143
|
-
/**
|
|
144
|
-
* @returns {import("./http-server/client/response.js").default}
|
|
145
|
-
*/
|
|
165
|
+
/** @returns {import("./http-server/client/response.js").default} */
|
|
146
166
|
response() { return this._response }
|
|
147
167
|
}
|
|
@@ -328,8 +328,8 @@ export default class VelociousDatabaseDriversBase {
|
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
|
-
* @param {
|
|
332
|
-
* @returns {string}
|
|
331
|
+
* @param {any} value
|
|
332
|
+
* @returns {number | string}
|
|
333
333
|
*/
|
|
334
334
|
quote(value) {
|
|
335
335
|
if (typeof value == "number") return value
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import BaseColumn from "../base-column.js"
|
|
2
4
|
import ColumnsIndex from "./columns-index.js"
|
|
3
5
|
import {digg} from "diggerize"
|
|
4
6
|
|
|
5
7
|
export default class VelociousDatabaseDriversMssqlColumn extends BaseColumn {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import("../base-table.js").default} table
|
|
10
|
+
* @param {Record<string, any>} data
|
|
11
|
+
*/
|
|
6
12
|
constructor(table, data) {
|
|
7
13
|
super()
|
|
8
14
|
this.data = data
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import QueryParserOptions from "../../query-parser/options.js"
|
|
2
4
|
|
|
3
5
|
export default class VelociousDatabaseDriversMssqlOptions extends QueryParserOptions {
|
|
6
|
+
/**
|
|
7
|
+
* @param {import("../../query-parser/options.js").OptionsObjectArgsType} options
|
|
8
|
+
*/
|
|
4
9
|
constructor(options) {
|
|
5
10
|
options.columnQuote = "\""
|
|
6
11
|
options.indexQuote = "\""
|
|
@@ -10,18 +15,30 @@ export default class VelociousDatabaseDriversMssqlOptions extends QueryParserOpt
|
|
|
10
15
|
super(options)
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {any} string
|
|
20
|
+
* @returns {number | string}
|
|
21
|
+
*/
|
|
13
22
|
quote(string) {
|
|
14
23
|
if (!this.driver) throw new Error("Driver not set")
|
|
15
24
|
|
|
16
25
|
return this.driver.quote(string)
|
|
17
26
|
}
|
|
18
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} string
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
19
32
|
quoteColumnName(string) {
|
|
20
33
|
if (string.includes("[") || string.includes("]")) throw new Error(`Possible SQL injection in column name: ${string}`)
|
|
21
34
|
|
|
22
35
|
return `[${string}]`
|
|
23
36
|
}
|
|
24
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} databaseName
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
25
42
|
quoteDatabaseName(databaseName) {
|
|
26
43
|
if (typeof databaseName != "string") throw new Error(`Invalid database name given: ${databaseName}`)
|
|
27
44
|
if (databaseName.includes("[") || databaseName.includes("]")) throw new Error(`Possible SQL injection in database name: ${databaseName}`)
|
|
@@ -29,12 +46,20 @@ export default class VelociousDatabaseDriversMssqlOptions extends QueryParserOpt
|
|
|
29
46
|
return `[${databaseName}]`
|
|
30
47
|
}
|
|
31
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} string
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
32
53
|
quoteIndexName(string) {
|
|
33
54
|
if (string.includes("[") || string.includes("]")) throw new Error(`Possible SQL injection in index name: ${string}`)
|
|
34
55
|
|
|
35
56
|
return `[${string}]`
|
|
36
57
|
}
|
|
37
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} string
|
|
61
|
+
* @returns {string}
|
|
62
|
+
*/
|
|
38
63
|
quoteTableName(string) {
|
|
39
64
|
if (string.includes("[") || string.includes("]")) throw new Error(`Possible SQL injection in table name: ${string}`)
|
|
40
65
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import QueryParserOptions from "../../query-parser/options.js"
|
|
2
4
|
|
|
3
5
|
export default class VelociousDatabaseDriversMysqlOptions extends QueryParserOptions {
|
|
6
|
+
/**
|
|
7
|
+
* @param {import("../../query-parser/options.js").OptionsObjectArgsType} options
|
|
8
|
+
*/
|
|
4
9
|
constructor(options) {
|
|
5
10
|
options.columnQuote = "`"
|
|
6
11
|
options.indexQuote = "`"
|
|
@@ -10,6 +15,10 @@ export default class VelociousDatabaseDriversMysqlOptions extends QueryParserOpt
|
|
|
10
15
|
super(options)
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {any} string
|
|
20
|
+
* @returns {number | string}
|
|
21
|
+
*/
|
|
13
22
|
quote(string) {
|
|
14
23
|
if (!this.driver) throw new Error("Driver not set")
|
|
15
24
|
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import BaseColumn from "../base-column.js"
|
|
2
4
|
import ColumnsIndex from "./columns-index.js"
|
|
3
5
|
import {digg} from "diggerize"
|
|
4
6
|
|
|
5
7
|
export default class VelociousDatabaseDriversPgsqlColumn extends BaseColumn {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import("../base-table.js").default} table
|
|
10
|
+
* @param {Record<string, any>} data
|
|
11
|
+
*/
|
|
6
12
|
constructor(table, data) {
|
|
7
13
|
super()
|
|
8
14
|
this.data = data
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import QueryParserOptions from "../../query-parser/options.js"
|
|
2
4
|
|
|
3
5
|
export default class VelociousDatabaseDriversPgsqlOptions extends QueryParserOptions {
|
|
6
|
+
/**
|
|
7
|
+
* @param {import("../../query-parser/options.js").OptionsObjectArgsType} options
|
|
8
|
+
*/
|
|
4
9
|
constructor(options) {
|
|
5
10
|
options.columnQuote = "\""
|
|
6
11
|
options.indexQuote = "\""
|
|
@@ -10,6 +15,10 @@ export default class VelociousDatabaseDriversPgsqlOptions extends QueryParserOpt
|
|
|
10
15
|
super(options)
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} string
|
|
20
|
+
* @returns {number | string}
|
|
21
|
+
*/
|
|
13
22
|
quote(string) {
|
|
14
23
|
if (!this.driver) throw new Error("Driver not set")
|
|
15
24
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import CreateDatabaseBase from "../../../query/create-database-base.js"
|
|
2
|
-
import {digs} from "diggerize"
|
|
3
4
|
|
|
4
5
|
export default class VelociousDatabaseConnectionDriversPgsqlSqlCreateDatabase extends CreateDatabaseBase {
|
|
5
6
|
toSql() {
|
|
@@ -10,8 +11,8 @@ export default class VelociousDatabaseConnectionDriversPgsqlSqlCreateDatabase ex
|
|
|
10
11
|
if (this.ifNotExists) {
|
|
11
12
|
sqls.push("CREATE EXTENSION IF NOT EXISTS dblink")
|
|
12
13
|
|
|
13
|
-
const connectArgs = this._driver.
|
|
14
|
-
const {password,
|
|
14
|
+
const connectArgs = this._driver.getArgs()
|
|
15
|
+
const {password, username} = connectArgs
|
|
15
16
|
const port = connectArgs.port || 5432
|
|
16
17
|
const sql = `
|
|
17
18
|
DO
|
|
@@ -20,7 +21,7 @@ export default class VelociousDatabaseConnectionDriversPgsqlSqlCreateDatabase ex
|
|
|
20
21
|
IF EXISTS (SELECT FROM ${options.quoteTableName("pg_database")} WHERE ${options.quoteColumnName("datname")} = ${options.quote(databaseName)}) THEN
|
|
21
22
|
RAISE NOTICE 'Database already exists'; -- optional
|
|
22
23
|
ELSE
|
|
23
|
-
PERFORM dblink_connect('host=localhost port=' || ${port} || ' user=' || ${options.quote(
|
|
24
|
+
PERFORM dblink_connect('host=localhost port=' || ${port} || ' user=' || ${options.quote(username)} || ' password=' || ${options.quote(password)} || ' dbname=' || current_database());
|
|
24
25
|
PERFORM dblink_exec('CREATE DATABASE ' || ${options.quote(databaseName)});
|
|
25
26
|
END IF;
|
|
26
27
|
END
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import BaseTable from "../base-table.js"
|
|
2
4
|
import Column from "./column.js"
|
|
3
5
|
import ColumnsIndex from "./columns-index.js"
|
|
4
6
|
import ForeignKey from "./foreign-key.js"
|
|
5
7
|
|
|
6
8
|
export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
|
|
9
|
+
/**
|
|
10
|
+
* @param {import("../base.js").default} driver
|
|
11
|
+
* @param {Record<string, any>} data
|
|
12
|
+
*/
|
|
7
13
|
constructor(driver, data) {
|
|
8
14
|
super()
|
|
9
15
|
this.data = data
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import BaseColumnsIndex from "../base-columns-index.js"
|
|
2
4
|
import {digg} from "diggerize"
|
|
3
5
|
import TableIndex from "../../table-data/table-index.js"
|
|
4
6
|
|
|
5
7
|
export default class VelociousDatabaseDriversSqliteColumnsIndex extends BaseColumnsIndex {
|
|
6
|
-
constructor(table, data) {
|
|
7
|
-
super()
|
|
8
|
-
this.data = data
|
|
9
|
-
this.table = table
|
|
10
|
-
}
|
|
11
|
-
|
|
12
8
|
getColumnNames() {
|
|
13
9
|
return digg(this, "data", "columnNames")
|
|
14
10
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import debounce from "debounce"
|
|
2
4
|
import query from "./query"
|
|
3
5
|
|
|
4
6
|
export default class VelociousDatabaseDriversSqliteConnectionSqlJs {
|
|
7
|
+
/**
|
|
8
|
+
* @param {import("../base.js").default} driver
|
|
9
|
+
* @param {import("sql.js").Database} connection
|
|
10
|
+
*/
|
|
5
11
|
constructor(driver, connection) {
|
|
6
12
|
this.connection = connection
|
|
7
13
|
this.driver = driver
|
|
@@ -9,12 +15,15 @@ export default class VelociousDatabaseDriversSqliteConnectionSqlJs {
|
|
|
9
15
|
|
|
10
16
|
async close() {
|
|
11
17
|
await this.saveDatabase()
|
|
12
|
-
await this.connection.
|
|
13
|
-
this.connection = undefined
|
|
18
|
+
await this.connection.close()
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
async disconnect() { await this.saveDatabase() }
|
|
17
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} sql
|
|
25
|
+
* @returns {Promise<Record<string, any>[]>}
|
|
26
|
+
*/
|
|
18
27
|
async query(sql) {
|
|
19
28
|
const result = await query(this.connection, sql)
|
|
20
29
|
const downcasedSQL = sql.toLowerCase().trim()
|
|
@@ -30,6 +39,7 @@ export default class VelociousDatabaseDriversSqliteConnectionSqlJs {
|
|
|
30
39
|
saveDatabase = async () => {
|
|
31
40
|
const localStorageContent = this.connection.export()
|
|
32
41
|
|
|
42
|
+
// @ts-expect-error
|
|
33
43
|
await this.driver.betterLocalStorage.set(this.driver.localStorageName(), localStorageContent)
|
|
34
44
|
}
|
|
35
45
|
|