velocious 1.0.106 → 1.0.107

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.
Files changed (82) hide show
  1. package/package.json +3 -1
  2. package/peak_flow.yml +1 -0
  3. package/spec/cli/commands/db/migrate-spec.js +7 -2
  4. package/spec/cli/commands/test/test-files-finder-spec.js +2 -0
  5. package/spec/database/connection/drivers/mysql/query-parser-spec.js +3 -1
  6. package/spec/database/drivers/mysql/connection-spec.js +1 -1
  7. package/spec/database/record/find-or-create-spec.js +3 -3
  8. package/spec/database/record/find-spec.js +1 -1
  9. package/spec/database/record/instance-relationships/belongs-to-relationship-spec.js +1 -1
  10. package/spec/database/record/instance-relationships/has-many-relationship-spec.js +3 -3
  11. package/spec/database/record/instance-relationships/has-one-relationship-spec.js +1 -1
  12. package/spec/database/record/last-spec.js +2 -2
  13. package/spec/database/record/preloader/belongs-to-spec.js +1 -1
  14. package/spec/database/record/preloader/has-many-spec.js +4 -4
  15. package/spec/database/record/preloader/has-one-spec.js +1 -1
  16. package/spec/database/record/query-spec.js +8 -6
  17. package/spec/database/record/translation-fallbacks-spec.js +1 -1
  18. package/spec/dummy/src/config/configuration.example.js +1 -0
  19. package/spec/dummy/src/model-bases/account.js +2 -2
  20. package/spec/dummy/src/model-bases/authentication-token.js +3 -3
  21. package/spec/dummy/src/model-bases/project-detail.js +3 -3
  22. package/spec/dummy/src/model-bases/project-translation.js +3 -3
  23. package/spec/dummy/src/model-bases/project.js +12 -12
  24. package/spec/dummy/src/model-bases/task.js +3 -3
  25. package/spec/dummy/src/model-bases/user.js +9 -9
  26. package/spec/dummy/src/routes/projects/controller.js +1 -1
  27. package/spec/dummy/src/routes/tasks/controller.js +1 -3
  28. package/spec/http-server/client-spec.js +1 -1
  29. package/spec/http-server/get-spec.js +1 -1
  30. package/spec/http-server/post-spec.js +9 -9
  31. package/spec/http-server/root-get-spec.js +2 -1
  32. package/src/application.js +1 -0
  33. package/src/cli/base-command.js +1 -1
  34. package/src/cli/commands/db/create.js +1 -1
  35. package/src/cli/use-browser-cli.js +2 -0
  36. package/src/configuration-types.js +11 -6
  37. package/src/controller.js +1 -2
  38. package/src/database/drivers/base.js +9 -9
  39. package/src/database/drivers/mssql/index.js +11 -11
  40. package/src/database/drivers/mssql/options.js +10 -6
  41. package/src/database/drivers/mysql/index.js +8 -8
  42. package/src/database/drivers/mysql/options.js +10 -6
  43. package/src/database/drivers/pgsql/index.js +10 -10
  44. package/src/database/drivers/pgsql/options.js +9 -6
  45. package/src/database/drivers/sqlite/base.js +10 -10
  46. package/src/database/drivers/sqlite/connection-sql-js.js +2 -0
  47. package/src/database/drivers/sqlite/index.js +8 -2
  48. package/src/database/drivers/sqlite/index.native.js +5 -1
  49. package/src/database/drivers/sqlite/index.web.js +2 -1
  50. package/src/database/drivers/sqlite/options.js +10 -7
  51. package/src/database/drivers/sqlite/sql/alter-table.js +3 -3
  52. package/src/database/migration/index.js +16 -5
  53. package/src/database/migrator.js +5 -1
  54. package/src/database/pool/base-methods-forward.js +0 -4
  55. package/src/database/query/alter-table-base.js +2 -2
  56. package/src/database/query/base.js +2 -2
  57. package/src/database/query/create-index-base.js +2 -2
  58. package/src/database/query/create-table-base.js +4 -4
  59. package/src/database/query/drop-table-base.js +2 -2
  60. package/src/database/query/index.js +2 -2
  61. package/src/database/record/index.js +11 -44
  62. package/src/database/record/instance-relationships/base.js +2 -2
  63. package/src/database/record/instance-relationships/has-many.js +1 -1
  64. package/src/database/use-database.js +1 -0
  65. package/src/environment-handlers/base.js +2 -2
  66. package/src/environment-handlers/browser.js +40 -18
  67. package/src/environment-handlers/node/cli/commands/destroy/migration.js +5 -1
  68. package/src/environment-handlers/node/cli/commands/generate/base-models.js +20 -9
  69. package/src/environment-handlers/node/cli/commands/generate/migration.js +5 -1
  70. package/src/environment-handlers/node/cli/commands/generate/model.js +5 -1
  71. package/src/environment-handlers/node/cli/commands/init.js +5 -1
  72. package/src/environment-handlers/node.js +1 -1
  73. package/src/http-server/client/index.js +2 -1
  74. package/src/http-server/client/params-to-object.js +0 -8
  75. package/src/http-server/client/request-buffer/index.js +1 -0
  76. package/src/routes/basic-route.js +1 -1
  77. package/src/testing/test-files-finder.js +1 -1
  78. package/src/testing/test-runner.js +3 -0
  79. package/src/testing/test.js +0 -2
  80. package/src/utils/with-tracked-stack-async-hooks.js +0 -2
  81. package/src/utils/with-tracked-stack.js +0 -2
  82. package/tsconfig.json +15 -0
@@ -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) {
@@ -1,4 +1,6 @@
1
+ // @ts-expect-error
1
2
  import React from "react"
3
+
2
4
  import BrowserCli from "./browser-cli.js"
3
5
  import restArgsError from "../utils/rest-args-error.js"
4
6
 
@@ -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 {object} config
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|number} 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 {import("../../query-parser/options.js").OptionsObjectArgsType} options
7
+ * @param {object} args
8
+ * @param {import("../base.js").default} args.driver
8
9
  */
9
- constructor(options) {
10
- options.columnQuote = "\""
11
- options.indexQuote = "\""
12
- options.stringQuote = "'"
13
- options.tableQuote = "\""
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 {import("../../query-parser/options.js").OptionsObjectArgsType} options
7
+ * @param {object} args
8
+ * @param {import("../base.js").default} args.driver
8
9
  */
9
- constructor(options) {
10
- options.columnQuote = "`"
11
- options.indexQuote = "`"
12
- options.stringQuote = "'"
13
- options.tableQuote = "`"
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({driver: this})
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("../../query-parser/options.js").OptionsObjectArgsType} options
7
+ * @param {import("../base.js").default} driver
8
8
  */
9
- constructor(options) {
10
- options.columnQuote = "\""
11
- options.indexQuote = "\""
12
- options.stringQuote = "'"
13
- options.tableQuote = "\""
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({driver: this})
220
+ if (!this._options) this._options = new Options(this)
221
221
 
222
222
  return this._options
223
223
  }
@@ -1,6 +1,8 @@
1
1
  // @ts-check
2
2
 
3
3
  import debounce from "debounce"
4
+
5
+ // @ts-expect-error
4
6
  import query from "./query"
5
7
 
6
8
  export default class VelociousDatabaseDriversSqliteConnectionSqlJs {
@@ -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
- this.connection = await open({
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("../../query-parser/options.js").OptionsObjectArgsType} options
7
+ * @param {import("../base.js").default} driver
8
8
  */
9
- constructor(options) {
10
- options.columnQuote = "`"
11
- options.indexQuote = "`"
12
- options.stringQuote = "'"
13
- options.tableQuote = "`"
9
+ constructor(driver) {
10
+ const optionsArgs = {
11
+ driver,
12
+ columnQuote: "`",
13
+ indexQuote: "`",
14
+ stringQuote: "'",
15
+ tableQuote: "`"
16
+ }
14
17
 
15
- super(options)
18
+ super(optionsArgs)
16
19
  }
17
20
 
18
21
  /**
@@ -23,7 +23,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
23
23
  }
24
24
 
25
25
  /**
26
- * @returns {string[]}
26
+ * @returns {Promise<string[]>}
27
27
  */
28
28
  async toSQLs() {
29
29
  const {tableData} = this
@@ -108,7 +108,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
108
108
  tableDataColumn.setForeignKey(foreignKey)
109
109
  }
110
110
 
111
- const createNewTableSQL = this.getDriver().createTableSql(newTableData)
111
+ const createNewTableSQL = await this.getDriver().createTableSql(newTableData)
112
112
  const insertSQL = `INSERT INTO ${options.quoteTableName(tempTableName)} (${newColumnsSQL}) SELECT ${oldColumnsSQL} FROM ${options.quoteTableName(tableName)}`
113
113
  const dropTableSQLs = `DROP TABLE ${options.quoteTableName(tableName)}`
114
114
  const renameTableSQL = `ALTER TABLE ${options.quoteTableName(tempTableName)} RENAME TO ${options.quoteTableName(tableName)}`
@@ -141,7 +141,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
141
141
  tableName,
142
142
  unique: actualTableIndex.getUnique()
143
143
  }
144
- const createIndexSQLs = new CreateIndexBase(createIndexArgs).toSQLs()
144
+ const createIndexSQLs = await new CreateIndexBase(createIndexArgs).toSQLs()
145
145
 
146
146
  for (const createIndexSQL of createIndexSQLs) {
147
147
  sqls.push(createIndexSQL)
@@ -135,7 +135,7 @@ export default class VelociousDatabaseMigration {
135
135
  },
136
136
  args
137
137
  )
138
- const sqls = this.getDriver().createIndexSQLs(createIndexArgs)
138
+ const sqls = await this.getDriver().createIndexSQLs(createIndexArgs)
139
139
 
140
140
  for (const sql of sqls) {
141
141
  await this.getDriver().query(sql)
@@ -246,14 +246,25 @@ export default class VelociousDatabaseMigration {
246
246
  * @property {CreateTableIdArgsType | false} [id]
247
247
  */
248
248
  /**
249
+ * @typedef {(TableData) => void} CreateTableCallbackType
250
+ */
251
+ /**
252
+ * @overload
253
+ * @param {string} tableName
254
+ * @param {CreateTableCallbackType} callback
255
+ * @returns {Promise<void>}
256
+ */
257
+ /**
258
+ * @overload
249
259
  * @param {string} tableName
250
- * @param {function(TableData) : void} arg1
260
+ * @param {CreateTableArgsType} args
261
+ * @param {CreateTableCallbackType} callback
251
262
  * @returns {Promise<void>}
252
263
  */
253
264
  /**
254
265
  * @param {string} tableName
255
- * @param {CreateTableArgsType} arg1
256
- * @param {function(TableData) : void} arg2
266
+ * @param {CreateTableArgsType | CreateTableCallbackType} arg1
267
+ * @param {CreateTableCallbackType | undefined} [arg2]
257
268
  * @returns {Promise<void>}
258
269
  */
259
270
  async createTable(tableName, arg1, arg2) {
@@ -297,7 +308,7 @@ export default class VelociousDatabaseMigration {
297
308
  callback(tableData)
298
309
  }
299
310
 
300
- const sqls = this.getDriver().createTableSql(tableData)
311
+ const sqls = await this.getDriver().createTableSql(tableData)
301
312
 
302
313
  for (const sql of sqls) {
303
314
  await this._db.query(sql)
@@ -56,7 +56,7 @@ export default class VelociousDatabaseMigrator {
56
56
 
57
57
  schemaMigrationsTable.string("version", {null: false, primaryKey: true})
58
58
 
59
- const createSchemaMigrationsTableSqls = db.createTableSql(schemaMigrationsTable)
59
+ const createSchemaMigrationsTableSqls = await db.createTableSql(schemaMigrationsTable)
60
60
 
61
61
  for (const createSchemaMigrationsTableSql of createSchemaMigrationsTableSqls) {
62
62
  await db.query(createSchemaMigrationsTableSql)
@@ -64,6 +64,10 @@ export default class VelociousDatabaseMigrator {
64
64
  }
65
65
  }
66
66
 
67
+ async dropDatabase() {
68
+ throw new Error("Not implemented yet")
69
+ }
70
+
67
71
  /**
68
72
  * @param {string} dbIdentifier
69
73
  * @param {number} version
@@ -28,16 +28,12 @@ export default function baseMethodsForward(PoolBase) {
28
28
  ]
29
29
 
30
30
  for (const forwardMethod of forwardMethods) {
31
- // @ts-expect-error
32
31
  PoolBase.prototype[forwardMethod] = function(...args) {
33
32
  const connection = this.getCurrentConnection()
34
-
35
- // @ts-expect-error
36
33
  const connectionMethod = connection[forwardMethod]
37
34
 
38
35
  if (!connectionMethod) throw new Error(`${forwardMethod} isn't defined on driver`)
39
36
 
40
- // @ts-expect-error
41
37
  return connection[forwardMethod](...args)
42
38
  }
43
39
  }