velocious 1.0.106 → 1.0.108
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 +3 -1
- package/peak_flow.yml +1 -0
- package/spec/cli/commands/db/migrate-spec.js +7 -2
- package/spec/cli/commands/test/test-files-finder-spec.js +2 -0
- package/spec/database/connection/drivers/mysql/query-parser-spec.js +3 -1
- package/spec/database/drivers/mysql/connection-spec.js +1 -1
- package/spec/database/record/find-or-create-spec.js +3 -3
- package/spec/database/record/find-spec.js +1 -1
- package/spec/database/record/instance-relationships/belongs-to-relationship-spec.js +1 -1
- package/spec/database/record/instance-relationships/has-many-relationship-spec.js +3 -3
- package/spec/database/record/instance-relationships/has-one-relationship-spec.js +1 -1
- package/spec/database/record/last-spec.js +2 -2
- package/spec/database/record/preloader/belongs-to-spec.js +1 -1
- package/spec/database/record/preloader/has-many-spec.js +4 -4
- package/spec/database/record/preloader/has-one-spec.js +1 -1
- package/spec/database/record/query-spec.js +8 -6
- package/spec/database/record/translation-fallbacks-spec.js +1 -1
- package/spec/dummy/src/config/configuration.example.js +1 -0
- package/spec/dummy/src/config/routes.js +4 -0
- package/spec/dummy/src/model-bases/account.js +2 -2
- package/spec/dummy/src/model-bases/authentication-token.js +3 -3
- package/spec/dummy/src/model-bases/project-detail.js +3 -3
- package/spec/dummy/src/model-bases/project-translation.js +3 -3
- package/spec/dummy/src/model-bases/project.js +12 -12
- package/spec/dummy/src/model-bases/task.js +3 -3
- package/spec/dummy/src/model-bases/user.js +9 -9
- package/spec/dummy/src/routes/api/controller.js +9 -0
- package/spec/dummy/src/routes/projects/controller.js +1 -1
- package/spec/dummy/src/routes/tasks/controller.js +1 -3
- package/spec/http-server/client-spec.js +1 -1
- package/spec/http-server/get-spec.js +1 -1
- package/spec/http-server/namespace-spec.js +17 -0
- package/spec/http-server/post-spec.js +9 -9
- package/spec/http-server/root-get-spec.js +2 -1
- package/src/application.js +1 -0
- package/src/cli/base-command.js +1 -1
- package/src/cli/commands/db/create.js +1 -1
- package/src/cli/use-browser-cli.js +2 -0
- package/src/configuration-types.js +11 -6
- package/src/controller.js +1 -2
- package/src/database/drivers/base.js +9 -9
- package/src/database/drivers/mssql/index.js +11 -11
- package/src/database/drivers/mssql/options.js +10 -6
- package/src/database/drivers/mysql/index.js +8 -8
- package/src/database/drivers/mysql/options.js +10 -6
- package/src/database/drivers/pgsql/index.js +10 -10
- package/src/database/drivers/pgsql/options.js +9 -6
- package/src/database/drivers/sqlite/base.js +10 -10
- package/src/database/drivers/sqlite/connection-sql-js.js +2 -0
- package/src/database/drivers/sqlite/index.js +8 -2
- package/src/database/drivers/sqlite/index.native.js +5 -1
- package/src/database/drivers/sqlite/index.web.js +2 -1
- package/src/database/drivers/sqlite/options.js +10 -7
- package/src/database/drivers/sqlite/sql/alter-table.js +3 -3
- package/src/database/migration/index.js +16 -5
- package/src/database/migrator.js +5 -1
- package/src/database/pool/base-methods-forward.js +0 -4
- package/src/database/query/alter-table-base.js +2 -2
- package/src/database/query/base.js +2 -2
- package/src/database/query/create-index-base.js +2 -2
- package/src/database/query/create-table-base.js +4 -4
- package/src/database/query/drop-table-base.js +2 -2
- package/src/database/query/index.js +2 -2
- package/src/database/record/index.js +11 -44
- package/src/database/record/instance-relationships/base.js +2 -2
- package/src/database/record/instance-relationships/has-many.js +1 -1
- package/src/database/use-database.js +1 -0
- package/src/environment-handlers/base.js +2 -2
- package/src/environment-handlers/browser.js +40 -18
- package/src/environment-handlers/node/cli/commands/destroy/migration.js +5 -1
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +20 -9
- package/src/environment-handlers/node/cli/commands/generate/migration.js +5 -1
- package/src/environment-handlers/node/cli/commands/generate/model.js +5 -1
- package/src/environment-handlers/node/cli/commands/init.js +5 -1
- package/src/environment-handlers/node.js +1 -1
- package/src/http-server/client/index.js +2 -1
- package/src/http-server/client/params-to-object.js +0 -8
- package/src/http-server/client/request-buffer/index.js +1 -0
- package/src/routes/basic-route.js +1 -1
- package/src/routes/namespace-route.js +1 -1
- package/src/testing/test-files-finder.js +1 -1
- package/src/testing/test-runner.js +3 -0
- package/src/testing/test.js +0 -2
- package/src/utils/with-tracked-stack-async-hooks.js +0 -2
- package/src/utils/with-tracked-stack.js +0 -2
- package/tsconfig.json +15 -0
|
@@ -6,7 +6,7 @@ import wait from "awaitery/src/wait.js"
|
|
|
6
6
|
import Dummy from "../dummy/index.js"
|
|
7
7
|
import Project from "../dummy/src/models/project.js"
|
|
8
8
|
|
|
9
|
-
describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate: true}}, () => {
|
|
9
|
+
describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate: true}}, async () => {
|
|
10
10
|
it("handles post requests", async () => {
|
|
11
11
|
await Dummy.run(async () => {
|
|
12
12
|
for (let i = 0; i <= 5; i++) {
|
|
@@ -17,7 +17,7 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
17
17
|
body: postData,
|
|
18
18
|
headers: {
|
|
19
19
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
20
|
-
"Content-Length": Buffer.byteLength(postData)
|
|
20
|
+
"Content-Length": Buffer.byteLength(postData).toString()
|
|
21
21
|
},
|
|
22
22
|
method: "POST"
|
|
23
23
|
}
|
|
@@ -27,7 +27,7 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
27
27
|
|
|
28
28
|
await wait(100) // Wait a bit to ensure the database connections are in sync
|
|
29
29
|
|
|
30
|
-
const createdProject = await Project.preload({translations: true}).find(projectID)
|
|
30
|
+
const createdProject = /** @type {Project} */ (await Project.preload({translations: true}).find(projectID))
|
|
31
31
|
|
|
32
32
|
expect(createdProject.name()).toEqual("Test create project")
|
|
33
33
|
}
|
|
@@ -44,18 +44,18 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
44
44
|
body: postData,
|
|
45
45
|
headers: {
|
|
46
46
|
"Content-Type": "application/json",
|
|
47
|
-
"Content-Length": Buffer.byteLength(postData)
|
|
47
|
+
"Content-Length": Buffer.byteLength(postData).toString()
|
|
48
48
|
},
|
|
49
49
|
method: "POST"
|
|
50
50
|
}
|
|
51
51
|
)
|
|
52
|
-
const data = await response.json()
|
|
52
|
+
const data = /** @type {Record<string, any>} */ (await response.json())
|
|
53
53
|
|
|
54
54
|
expect(data.status).toEqual("success")
|
|
55
55
|
|
|
56
56
|
await wait(100) // Wait a bit to ensure the database connections are in sync
|
|
57
57
|
|
|
58
|
-
const createdProject = await Project.preload({translations: true}).last()
|
|
58
|
+
const createdProject = /** @type {Project} */ (await Project.preload({translations: true}).last())
|
|
59
59
|
|
|
60
60
|
expect(createdProject.name()).toEqual("Test create project")
|
|
61
61
|
}
|
|
@@ -67,7 +67,7 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
67
67
|
for (let i = 0; i <= 5; i++) {
|
|
68
68
|
const body = new FormData()
|
|
69
69
|
|
|
70
|
-
body.append("project[creating_user_reference]", 150123)
|
|
70
|
+
body.append("project[creating_user_reference]", "150123")
|
|
71
71
|
body.append("project[name]", "Test create project")
|
|
72
72
|
|
|
73
73
|
const response = await fetch(
|
|
@@ -77,13 +77,13 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
77
77
|
method: "POST"
|
|
78
78
|
}
|
|
79
79
|
)
|
|
80
|
-
const data = await response.json()
|
|
80
|
+
const data = /** @type {Record<string, any>} */ (await response.json())
|
|
81
81
|
|
|
82
82
|
expect(data.status).toEqual("success")
|
|
83
83
|
|
|
84
84
|
await wait(100) // Wait a bit to ensure the database connections are in sync
|
|
85
85
|
|
|
86
|
-
const createdProject = await Project.preload({translations: true}).last()
|
|
86
|
+
const createdProject = /** @type {Project} */ (await Project.preload({translations: true}).last())
|
|
87
87
|
|
|
88
88
|
expect(createdProject.creatingUserReference()).toEqual("150123")
|
|
89
89
|
expect(createdProject.name()).toEqual("Test create project")
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import {describe, it} from "../../src/testing/test.js"
|
|
1
2
|
import fetch from "node-fetch"
|
|
2
3
|
import Dummy from "../dummy/index.js"
|
|
3
4
|
|
|
4
|
-
describe("HttpServer - root get", {databaseCleaning: {transaction: false, truncate: true}}, () => {
|
|
5
|
+
describe("HttpServer - root get", {databaseCleaning: {transaction: false, truncate: true}}, async () => {
|
|
5
6
|
it("handles root get requests", async () => {
|
|
6
7
|
await Dummy.run(async () => {
|
|
7
8
|
for (let i = 0; i <= 5; i++) {
|
package/src/application.js
CHANGED
package/src/cli/base-command.js
CHANGED
|
@@ -59,7 +59,7 @@ export default class DbCreate extends BaseCommand{
|
|
|
59
59
|
|
|
60
60
|
schemaMigrationsTable.string("version", {null: false, primaryKey: true})
|
|
61
61
|
|
|
62
|
-
const createSchemaMigrationsTableSqls = this.databaseConnection.createTableSql(schemaMigrationsTable)
|
|
62
|
+
const createSchemaMigrationsTableSqls = await this.databaseConnection.createTableSql(schemaMigrationsTable)
|
|
63
63
|
|
|
64
64
|
for (const createSchemaMigrationsTableSql of createSchemaMigrationsTableSqls) {
|
|
65
65
|
if (this.args.testing) {
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @typedef {object} DatabaseConfigurationType
|
|
23
|
+
* @property {string} [database]
|
|
24
|
+
* @property {typeof import("./database/drivers/base.js").default} [driver]
|
|
25
|
+
* @property {typeof import("./database/pool/base.js").default} [poolType]
|
|
23
26
|
* @property {function() : void} [getConnection]
|
|
24
27
|
* @property {string} [host]
|
|
25
28
|
* @property {boolean} [migrations]
|
|
@@ -29,6 +32,9 @@
|
|
|
29
32
|
* @property {object} [record]
|
|
30
33
|
* @property {boolean} [record.transactions]
|
|
31
34
|
* @property {boolean} [reset]
|
|
35
|
+
* @property {object} [sqlConfig]
|
|
36
|
+
* @property {string} [type]
|
|
37
|
+
* @property {string} [useDatabase]
|
|
32
38
|
* @property {string} [username]
|
|
33
39
|
*/
|
|
34
40
|
|
|
@@ -38,19 +44,18 @@
|
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* @typedef {object} ConfigurationArgsType
|
|
41
|
-
* @property {object} args
|
|
42
47
|
* @property {CorsType} [cors]
|
|
43
|
-
* @property {{[key: string]: DatabaseConfigurationType}} database
|
|
44
|
-
* @property {boolean} debug
|
|
48
|
+
* @property {{[key: string]: {[key: string]: DatabaseConfigurationType}}} database
|
|
49
|
+
* @property {boolean} [debug]
|
|
45
50
|
* @property {string} directory
|
|
46
|
-
* @property {string} environment
|
|
51
|
+
* @property {string} [environment]
|
|
47
52
|
* @property {import("./environment-handlers/base.js").default} environmentHandler
|
|
48
53
|
* @property {function({configuration: import("./configuration.js").default, type: string}) : void} initializeModels
|
|
49
|
-
* @property {InitializersType} initializers
|
|
54
|
+
* @property {InitializersType} [initializers]
|
|
50
55
|
* @property {string | function() : string} locale
|
|
51
56
|
* @property {string[]} locales
|
|
52
57
|
* @property {LocaleFallbacksType} localeFallbacks
|
|
53
|
-
* @property {string} testing
|
|
58
|
+
* @property {string} [testing]
|
|
54
59
|
*/
|
|
55
60
|
|
|
56
61
|
export const nothing = {}
|
package/src/controller.js
CHANGED
|
@@ -84,7 +84,6 @@ export default class VelociousController {
|
|
|
84
84
|
|
|
85
85
|
if (beforeActions) {
|
|
86
86
|
for (const beforeActionName of beforeActions) {
|
|
87
|
-
// @ts-expect-error
|
|
88
87
|
const beforeAction = currentControllerClass.prototype[beforeActionName]
|
|
89
88
|
|
|
90
89
|
if (!beforeAction) throw new Error(`No such before action: ${beforeActionName}`)
|
|
@@ -111,7 +110,7 @@ export default class VelociousController {
|
|
|
111
110
|
/**
|
|
112
111
|
* @param {object} [args]
|
|
113
112
|
* @param {object} [args.json]
|
|
114
|
-
* @param {number} [args.status]
|
|
113
|
+
* @param {number | string} [args.status]
|
|
115
114
|
* @returns {Promise<void>}
|
|
116
115
|
*/
|
|
117
116
|
async render({json, status, ...restArgs} = {}) {
|
|
@@ -54,7 +54,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
54
54
|
idSeq = undefined
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* @param {
|
|
57
|
+
* @param {import("../../configuration-types.js").DatabaseConfigurationType} config
|
|
58
58
|
* @param {import("../../configuration.js").default} configuration
|
|
59
59
|
*/
|
|
60
60
|
constructor(config, configuration) {
|
|
@@ -125,9 +125,9 @@ export default class VelociousDatabaseDriversBase {
|
|
|
125
125
|
/**
|
|
126
126
|
* @abstract
|
|
127
127
|
* @param {CreateIndexSqlArgs} indexData
|
|
128
|
-
* @returns {string[]}
|
|
128
|
+
* @returns {Promise<string[]>}
|
|
129
129
|
*/
|
|
130
|
-
createIndexSQLs(indexData) { // eslint-disable-line no-unused-vars
|
|
130
|
+
async createIndexSQLs(indexData) { // eslint-disable-line no-unused-vars
|
|
131
131
|
throw new Error("'createIndexSQLs' not implemented")
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -136,7 +136,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
136
136
|
* @returns {Promise<void>}
|
|
137
137
|
*/
|
|
138
138
|
async createTable(tableData) {
|
|
139
|
-
const sqls = this.createTableSql(tableData)
|
|
139
|
+
const sqls = await this.createTableSql(tableData)
|
|
140
140
|
|
|
141
141
|
for (const sql of sqls) {
|
|
142
142
|
await this.query(sql)
|
|
@@ -146,9 +146,9 @@ export default class VelociousDatabaseDriversBase {
|
|
|
146
146
|
/**
|
|
147
147
|
* @abstract
|
|
148
148
|
* @param {import("../table-data/index.js").default} tableData
|
|
149
|
-
* @returns {string[]}
|
|
149
|
+
* @returns {Promise<string[]>}
|
|
150
150
|
*/
|
|
151
|
-
createTableSql(tableData) { // eslint-disable-line no-unused-vars
|
|
151
|
+
async createTableSql(tableData) { // eslint-disable-line no-unused-vars
|
|
152
152
|
throw new Error("'createTableSql' not implemented")
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -177,7 +177,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
177
177
|
* @returns {Promise<void>}
|
|
178
178
|
*/
|
|
179
179
|
async dropTable(tableName, args) {
|
|
180
|
-
const sqls = this.dropTableSQLs(tableName, args)
|
|
180
|
+
const sqls = await this.dropTableSQLs(tableName, args)
|
|
181
181
|
|
|
182
182
|
for (const sql of sqls) {
|
|
183
183
|
await this.query(sql)
|
|
@@ -188,9 +188,9 @@ export default class VelociousDatabaseDriversBase {
|
|
|
188
188
|
* @abstract
|
|
189
189
|
* @param {string} tableName
|
|
190
190
|
* @param {DropTableSqlArgsType} [args]
|
|
191
|
-
* @returns {string[]}
|
|
191
|
+
* @returns {Promise<string[]>}
|
|
192
192
|
*/
|
|
193
|
-
dropTableSQLs(tableName, args) { // eslint-disable-line no-unused-vars
|
|
193
|
+
async dropTableSQLs(tableName, args) { // eslint-disable-line no-unused-vars
|
|
194
194
|
throw new Error("dropTableSQLs not implemented")
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -66,24 +66,24 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* @param {import("../base.js").CreateIndexSqlArgs} indexData
|
|
69
|
-
* @returns {string[]}
|
|
69
|
+
* @returns {Promise<string[]>}
|
|
70
70
|
*/
|
|
71
|
-
createIndexSQLs(indexData) {
|
|
71
|
+
async createIndexSQLs(indexData) {
|
|
72
72
|
const createArgs = Object.assign({driver: this}, indexData)
|
|
73
73
|
const createIndex = new CreateIndex(createArgs)
|
|
74
74
|
|
|
75
|
-
return createIndex.toSQLs()
|
|
75
|
+
return await createIndex.toSQLs()
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* @param {import("../../table-data/index.js").default} tableData
|
|
80
|
-
* @returns {string[]}
|
|
80
|
+
* @returns {Promise<string[]>}
|
|
81
81
|
*/
|
|
82
|
-
createTableSql(tableData) {
|
|
82
|
+
async createTableSql(tableData) {
|
|
83
83
|
const createArgs = {tableData, driver: this, indexInCreateTable: false}
|
|
84
84
|
const createTable = new CreateTable(createArgs)
|
|
85
85
|
|
|
86
|
-
return createTable.toSql()
|
|
86
|
+
return await createTable.toSql()
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -106,13 +106,13 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
106
106
|
/**
|
|
107
107
|
* @param {string} tableName
|
|
108
108
|
* @param {import("../base.js").DropTableSqlArgsType} [args]
|
|
109
|
-
* @returns {string[]}
|
|
109
|
+
* @returns {Promise<string[]>}
|
|
110
110
|
*/
|
|
111
|
-
dropTableSQLs(tableName, args = {}) {
|
|
111
|
+
async dropTableSQLs(tableName, args = {}) {
|
|
112
112
|
const dropArgs = Object.assign({tableName, driver: this}, args)
|
|
113
113
|
const dropTable = new DropTable(dropArgs)
|
|
114
114
|
|
|
115
|
-
return dropTable.toSQLs()
|
|
115
|
+
return await dropTable.toSQLs()
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
@@ -159,7 +159,6 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
// @ts-expect-error
|
|
163
162
|
return result.recordsets[0]
|
|
164
163
|
}
|
|
165
164
|
|
|
@@ -210,7 +209,7 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
210
209
|
quoteColumn(string) { return this.options().quoteColumnName(string) }
|
|
211
210
|
|
|
212
211
|
/**
|
|
213
|
-
* @param {string
|
|
212
|
+
* @param {string} string
|
|
214
213
|
* @returns {string}
|
|
215
214
|
*/
|
|
216
215
|
quoteTable(string) { return this.options().quoteTableName(string) }
|
|
@@ -287,6 +286,7 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
287
286
|
return lastInsertID
|
|
288
287
|
}
|
|
289
288
|
|
|
289
|
+
/** @returns {Options} */
|
|
290
290
|
options() {
|
|
291
291
|
if (!this._options) this._options = new Options({driver: this})
|
|
292
292
|
|
|
@@ -4,13 +4,17 @@ import QueryParserOptions from "../../query-parser/options.js"
|
|
|
4
4
|
|
|
5
5
|
export default class VelociousDatabaseDriversMssqlOptions extends QueryParserOptions {
|
|
6
6
|
/**
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} args
|
|
8
|
+
* @param {import("../base.js").default} args.driver
|
|
8
9
|
*/
|
|
9
|
-
constructor(
|
|
10
|
-
options
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
constructor({driver}) {
|
|
11
|
+
const options = {
|
|
12
|
+
driver,
|
|
13
|
+
columnQuote: "\"",
|
|
14
|
+
indexQuote: "\"",
|
|
15
|
+
stringQuote: "'",
|
|
16
|
+
tableQuote: "\""
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
super(options)
|
|
16
20
|
}
|
|
@@ -83,20 +83,20 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* @param {import("../base.js").CreateIndexSqlArgs} indexData
|
|
86
|
-
* @returns {string[]}
|
|
86
|
+
* @returns {Promise<string[]>}
|
|
87
87
|
*/
|
|
88
|
-
createIndexSQLs(indexData) {
|
|
88
|
+
async createIndexSQLs(indexData) {
|
|
89
89
|
const createArgs = Object.assign({driver: this}, indexData)
|
|
90
90
|
const createIndex = new CreateIndex(createArgs)
|
|
91
91
|
|
|
92
|
-
return createIndex.toSQLs()
|
|
92
|
+
return await createIndex.toSQLs()
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* @param {import("../../table-data/index.js").default} tableData
|
|
97
|
-
* @returns {string[]}
|
|
97
|
+
* @returns {Promise<string[]>}
|
|
98
98
|
*/
|
|
99
|
-
createTableSql(tableData) {
|
|
99
|
+
async createTableSql(tableData) {
|
|
100
100
|
const createArgs = {tableData, driver: this}
|
|
101
101
|
const createTable = new CreateTable(createArgs)
|
|
102
102
|
|
|
@@ -129,13 +129,13 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
129
129
|
/**
|
|
130
130
|
* @param {string} tableName
|
|
131
131
|
* @param {import("../base.js").DropTableSqlArgsType} [args]
|
|
132
|
-
* @returns {string[]}
|
|
132
|
+
* @returns {Promise<string[]>}
|
|
133
133
|
*/
|
|
134
|
-
dropTableSQLs(tableName, args = {}) {
|
|
134
|
+
async dropTableSQLs(tableName, args = {}) {
|
|
135
135
|
const dropArgs = Object.assign({tableName, driver: this}, args)
|
|
136
136
|
const dropTable = new DropTable(dropArgs)
|
|
137
137
|
|
|
138
|
-
return dropTable.toSQLs()
|
|
138
|
+
return await dropTable.toSQLs()
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
@@ -4,13 +4,17 @@ import QueryParserOptions from "../../query-parser/options.js"
|
|
|
4
4
|
|
|
5
5
|
export default class VelociousDatabaseDriversMysqlOptions extends QueryParserOptions {
|
|
6
6
|
/**
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} args
|
|
8
|
+
* @param {import("../base.js").default} args.driver
|
|
8
9
|
*/
|
|
9
|
-
constructor(
|
|
10
|
-
options
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
constructor({driver}) {
|
|
11
|
+
const options = {
|
|
12
|
+
driver,
|
|
13
|
+
columnQuote: "`",
|
|
14
|
+
indexQuote: "`",
|
|
15
|
+
stringQuote: "'",
|
|
16
|
+
tableQuote: "`"
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
super(options)
|
|
16
20
|
}
|
|
@@ -84,24 +84,24 @@ export default class VelociousDatabaseDriversPgsql extends Base{
|
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* @param {import("../base.js").CreateIndexSqlArgs} indexData
|
|
87
|
-
* @returns {string[]}
|
|
87
|
+
* @returns {Promise<string[]>}
|
|
88
88
|
*/
|
|
89
|
-
createIndexSQLs(indexData) {
|
|
89
|
+
async createIndexSQLs(indexData) {
|
|
90
90
|
const createArgs = Object.assign({driver: this}, indexData)
|
|
91
91
|
const createIndex = new CreateIndex(createArgs)
|
|
92
92
|
|
|
93
|
-
return createIndex.toSQLs()
|
|
93
|
+
return await createIndex.toSQLs()
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* @param {import("../../table-data/index.js").default} tableData
|
|
98
|
-
* @returns {string[]}
|
|
98
|
+
* @returns {Promise<string[]>}
|
|
99
99
|
*/
|
|
100
|
-
createTableSql(tableData) {
|
|
100
|
+
async createTableSql(tableData) {
|
|
101
101
|
const createArgs = {tableData, driver: this, indexInCreateTable: false}
|
|
102
102
|
const createTable = new CreateTable(createArgs)
|
|
103
103
|
|
|
104
|
-
return createTable.toSql()
|
|
104
|
+
return await createTable.toSql()
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
async currentDatabase() {
|
|
@@ -121,13 +121,13 @@ export default class VelociousDatabaseDriversPgsql extends Base{
|
|
|
121
121
|
/**
|
|
122
122
|
* @param {string} tableName
|
|
123
123
|
* @param {import("../base.js").DropTableSqlArgsType} [args]
|
|
124
|
-
* @returns {string[]}
|
|
124
|
+
* @returns {Promise<string[]>}
|
|
125
125
|
*/
|
|
126
|
-
dropTableSQLs(tableName, args = {}) {
|
|
126
|
+
async dropTableSQLs(tableName, args = {}) {
|
|
127
127
|
const dropArgs = Object.assign({tableName, driver: this}, args)
|
|
128
128
|
const dropTable = new DropTable(dropArgs)
|
|
129
129
|
|
|
130
|
-
return dropTable.toSQLs()
|
|
130
|
+
return await dropTable.toSQLs()
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
getType() { return "pgsql" }
|
|
@@ -228,7 +228,7 @@ export default class VelociousDatabaseDriversPgsql extends Base{
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
options() {
|
|
231
|
-
if (!this._options) this._options = new Options(
|
|
231
|
+
if (!this._options) this._options = new Options(this)
|
|
232
232
|
|
|
233
233
|
return this._options
|
|
234
234
|
}
|
|
@@ -4,13 +4,16 @@ import QueryParserOptions from "../../query-parser/options.js"
|
|
|
4
4
|
|
|
5
5
|
export default class VelociousDatabaseDriversPgsqlOptions extends QueryParserOptions {
|
|
6
6
|
/**
|
|
7
|
-
* @param {import("
|
|
7
|
+
* @param {import("../base.js").default} driver
|
|
8
8
|
*/
|
|
9
|
-
constructor(
|
|
10
|
-
options
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
constructor(driver) {
|
|
10
|
+
const options = {
|
|
11
|
+
driver,
|
|
12
|
+
columnQuote: "\"",
|
|
13
|
+
indexQuote: "\"",
|
|
14
|
+
stringQuote: "'",
|
|
15
|
+
tableQuote: "\""
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
super(options)
|
|
16
19
|
}
|
|
@@ -29,25 +29,25 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @param {import("../base.js").CreateIndexSqlArgs} indexData
|
|
32
|
-
* @returns {string[]}
|
|
32
|
+
* @returns {Promise<string[]>}
|
|
33
33
|
*/
|
|
34
|
-
createIndexSQLs(indexData) {
|
|
34
|
+
async createIndexSQLs(indexData) {
|
|
35
35
|
const createArgs = Object.assign({driver: this}, indexData)
|
|
36
36
|
const createIndex = new CreateIndex(createArgs)
|
|
37
37
|
|
|
38
|
-
return createIndex.toSQLs()
|
|
38
|
+
return await createIndex.toSQLs()
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* @abstract
|
|
43
43
|
* @param {import("../../table-data/index.js").default} tableData
|
|
44
|
-
* @returns {string[]}
|
|
44
|
+
* @returns {Promise<string[]>}
|
|
45
45
|
*/
|
|
46
|
-
createTableSql(tableData) {
|
|
46
|
+
async createTableSql(tableData) {
|
|
47
47
|
const createArgs = {tableData, driver: this, indexInCreateTable: false}
|
|
48
48
|
const createTable = new CreateTable(createArgs)
|
|
49
49
|
|
|
50
|
-
return createTable.toSql()
|
|
50
|
+
return await createTable.toSql()
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
currentDatabase() {
|
|
@@ -65,14 +65,14 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
65
65
|
/**
|
|
66
66
|
* @param {string} tableName
|
|
67
67
|
* @param {import("../base.js").DropTableSqlArgsType} [args]
|
|
68
|
-
* @returns {string[]}
|
|
68
|
+
* @returns {Promise<string[]>}
|
|
69
69
|
*/
|
|
70
|
-
dropTableSQLs(tableName, args = {}) {
|
|
70
|
+
async dropTableSQLs(tableName, args = {}) {
|
|
71
71
|
const driver = /** @type {import("../base.js").default} */ (this)
|
|
72
72
|
const dropArgs = Object.assign({tableName, driver}, args)
|
|
73
73
|
const dropTable = new DropTable(dropArgs)
|
|
74
74
|
|
|
75
|
-
return dropTable.toSQLs()
|
|
75
|
+
return await dropTable.toSQLs()
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -217,7 +217,7 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
options() {
|
|
220
|
-
if (!this._options) this._options = new Options(
|
|
220
|
+
if (!this._options) this._options = new Options(this)
|
|
221
221
|
|
|
222
222
|
return this._options
|
|
223
223
|
}
|
|
@@ -8,6 +8,9 @@ import {open} from "sqlite"
|
|
|
8
8
|
import Base from "./base.js"
|
|
9
9
|
|
|
10
10
|
export default class VelociousDatabaseDriversSqliteNode extends Base {
|
|
11
|
+
/** @type {import("sqlite3").Database | undefined} */
|
|
12
|
+
connection = undefined
|
|
13
|
+
|
|
11
14
|
async connect() {
|
|
12
15
|
const args = this.getArgs()
|
|
13
16
|
const databasePath = `${this.getConfiguration().getDirectory()}/db/${this.localStorageName()}.sqlite`
|
|
@@ -16,10 +19,11 @@ export default class VelociousDatabaseDriversSqliteNode extends Base {
|
|
|
16
19
|
await fs.unlink(databasePath)
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
this.connection = /** @type {import("sqlite3").Database} */ (await open({
|
|
20
24
|
filename: databasePath,
|
|
21
25
|
driver: sqlite3.Database
|
|
22
|
-
})
|
|
26
|
+
}))
|
|
23
27
|
await this.registerVersion()
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -41,6 +45,8 @@ export default class VelociousDatabaseDriversSqliteNode extends Base {
|
|
|
41
45
|
* @returns {Promise<Record<string, any>[]>}
|
|
42
46
|
*/
|
|
43
47
|
async _queryActual(sql) {
|
|
48
|
+
if (!this.connection) throw new Error("No connection")
|
|
49
|
+
|
|
44
50
|
return await query(this.connection, sql)
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
import envSense from "env-sense/src/use-env-sense.js"
|
|
3
|
+
|
|
4
|
+
// @ts-expect-error
|
|
3
5
|
import query from "./query"
|
|
6
|
+
|
|
7
|
+
// @ts-expect-error
|
|
4
8
|
import * as SQLite from "expo-sqlite"
|
|
5
9
|
|
|
6
|
-
import Base from "./base"
|
|
10
|
+
import Base from "./base.js"
|
|
7
11
|
|
|
8
12
|
export default class VelociousDatabaseDriversSqliteNative extends Base {
|
|
9
13
|
async connect() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import BetterLocalStorage from "better-localstorage"
|
|
4
|
-
import ConnectionSqlJs from "./connection-sql-js"
|
|
4
|
+
import ConnectionSqlJs from "./connection-sql-js.js"
|
|
5
5
|
import initSqlJs from "sql.js"
|
|
6
6
|
|
|
7
7
|
import Base from "./base.js"
|
|
@@ -36,6 +36,7 @@ export default class VelociousDatabaseDriversSqliteWeb extends Base {
|
|
|
36
36
|
await this.getConnection().close()
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** @returns {ConnectionSqlJs | any} */
|
|
39
40
|
getConnection() {
|
|
40
41
|
if (this.args?.getConnection) {
|
|
41
42
|
return this.args.getConnection()
|
|
@@ -4,15 +4,18 @@ import QueryParserOptions from "../../query-parser/options.js"
|
|
|
4
4
|
|
|
5
5
|
export default class VelociousDatabaseDriversSqliteOptions extends QueryParserOptions {
|
|
6
6
|
/**
|
|
7
|
-
* @param {import("
|
|
7
|
+
* @param {import("../base.js").default} driver
|
|
8
8
|
*/
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
constructor(driver) {
|
|
10
|
+
const optionsArgs = {
|
|
11
|
+
driver,
|
|
12
|
+
columnQuote: "`",
|
|
13
|
+
indexQuote: "`",
|
|
14
|
+
stringQuote: "'",
|
|
15
|
+
tableQuote: "`"
|
|
16
|
+
}
|
|
14
17
|
|
|
15
|
-
super(
|
|
18
|
+
super(optionsArgs)
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|