velocious 1.0.5 → 1.0.6

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 (69) hide show
  1. package/package.json +5 -3
  2. package/spec/cli/commands/db/create-spec.mjs +1 -1
  3. package/spec/cli/commands/db/migrate-spec.mjs +2 -0
  4. package/spec/database/record/create-spec.mjs +9 -0
  5. package/spec/database/record/find-spec.mjs +0 -1
  6. package/spec/database/record/query-spec.mjs +37 -0
  7. package/spec/dummy/index.mjs +14 -2
  8. package/spec/dummy/src/config/configuration.example.mjs +16 -1
  9. package/spec/dummy/src/config/configuration.peakflow.mjs +16 -1
  10. package/spec/dummy/src/database/migrations/20230728075328-create-projects.mjs +0 -1
  11. package/spec/dummy/src/database/migrations/20230728075329-create-tasks.mjs +0 -1
  12. package/spec/dummy/src/database/migrations/20250605133926-create-project-translations.mjs +16 -0
  13. package/spec/dummy/src/models/project.mjs +9 -0
  14. package/spec/dummy/src/models/task.mjs +5 -1
  15. package/src/big-brother.mjs +37 -0
  16. package/src/cli/commands/db/create.mjs +8 -6
  17. package/src/cli/commands/db/migrate.mjs +1 -2
  18. package/src/cli/commands/generate/migration.mjs +1 -1
  19. package/src/cli/commands/generate/model.mjs +1 -1
  20. package/src/configuration.mjs +39 -3
  21. package/src/database/drivers/base.mjs +21 -2
  22. package/src/database/drivers/mysql/column.mjs +8 -0
  23. package/src/database/drivers/mysql/index.mjs +34 -2
  24. package/src/database/drivers/mysql/options.mjs +1 -0
  25. package/src/database/drivers/mysql/query-parser.mjs +2 -23
  26. package/src/database/drivers/mysql/table.mjs +25 -0
  27. package/src/database/drivers/sqlite/base.mjs +76 -4
  28. package/src/database/drivers/sqlite/column.mjs +10 -0
  29. package/src/database/drivers/sqlite/index.native.mjs +19 -22
  30. package/src/database/drivers/sqlite/index.web.mjs +27 -17
  31. package/src/database/drivers/sqlite/options.mjs +2 -1
  32. package/src/database/drivers/sqlite/query-parser.mjs +2 -23
  33. package/src/database/drivers/sqlite/query.native.mjs +16 -1
  34. package/src/database/drivers/sqlite/query.web.mjs +27 -2
  35. package/src/database/drivers/sqlite/sql/create-index.mjs +4 -0
  36. package/src/database/drivers/sqlite/table.mjs +16 -1
  37. package/src/database/initializer-from-require-context.mjs +21 -0
  38. package/src/database/migration/index.mjs +34 -2
  39. package/src/database/migrator.mjs +4 -2
  40. package/src/database/pool/base.mjs +5 -0
  41. package/src/database/query/base.mjs +2 -1
  42. package/src/database/query/create-index-base.mjs +50 -0
  43. package/src/database/query/create-table-base.mjs +40 -17
  44. package/src/database/query/index.mjs +83 -21
  45. package/src/database/query/preloader/belongs-to.mjs +52 -0
  46. package/src/database/query/preloader/has-many.mjs +55 -0
  47. package/src/database/query/preloader.mjs +41 -0
  48. package/src/database/query/where-base.mjs +9 -0
  49. package/src/database/query/where-hash.mjs +35 -0
  50. package/src/database/query/where-plain.mjs +13 -0
  51. package/src/database/query-parser/base-query-parser.mjs +33 -0
  52. package/src/database/query-parser/group-parser.mjs +40 -0
  53. package/src/database/query-parser/joins-parser.mjs +48 -7
  54. package/src/database/query-parser/limit-parser.mjs +40 -0
  55. package/src/database/query-parser/options.mjs +2 -1
  56. package/src/database/query-parser/order-parser.mjs +39 -0
  57. package/src/database/query-parser/select-parser.mjs +5 -1
  58. package/src/database/query-parser/where-parser.mjs +39 -0
  59. package/src/database/record/index.mjs +464 -29
  60. package/src/database/record/instance-relationships/base.mjs +28 -0
  61. package/src/database/record/instance-relationships/belongs-to.mjs +20 -0
  62. package/src/database/record/instance-relationships/has-many.mjs +47 -0
  63. package/src/database/record/relationships/base.mjs +32 -0
  64. package/src/database/record/relationships/belongs-to.mjs +12 -0
  65. package/src/database/record/relationships/has-many.mjs +12 -0
  66. package/src/database/table-data/index.mjs +15 -25
  67. package/src/http-server/worker-handler/worker-thread.mjs +7 -4
  68. package/src/templates/generate-model.mjs +3 -1
  69. package/src/utils/rest-args-error.mjs +9 -0
@@ -0,0 +1,32 @@
1
+ export default class VelociousDatabaseRecordBaseRelationship {
2
+ constructor({className, configuration, foreignKey, klass, modelClass, relationshipName, through, type, ...restArgs}) {
3
+ const restArgsKeys = Object.keys(restArgs)
4
+
5
+ if (restArgsKeys.length > 0) throw new Error(`Unknown args given: ${restArgsKeys.join(", ")}`)
6
+ if (!modelClass) throw new Error(`'modelClass' wasn't given for ${relationshipName}`)
7
+ if (!className && !klass) throw new Error(`Neither 'className' or 'klass' was given for ${modelClass.name}#${relationshipName}`)
8
+
9
+ this.className = className
10
+ this.configuration = configuration
11
+ this.foreignKey = foreignKey
12
+ this.klass = klass
13
+ this.modelClass = modelClass
14
+ this.relationshipName = relationshipName
15
+ this.through = through
16
+ this.type = type
17
+ }
18
+
19
+ getRelationshipName = () => this.relationshipName
20
+ getPrimaryKey = () => "id" // TODO: Support custom given primary key
21
+ getType = () => this.type
22
+
23
+ getTargetModelClass() {
24
+ if (this.className) {
25
+ return this.modelClass._getConfiguration().getModelClass(this.className)
26
+ } else if (this.klass) {
27
+ return this.klass
28
+ }
29
+
30
+ throw new Error("Couldn't figure out the target model class")
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import BaseRelationship from "./base.mjs"
2
+ import * as inflection from "inflection"
3
+
4
+ export default class VelociousDatabaseRecordBelongsToRelationship extends BaseRelationship {
5
+ getForeignKey() {
6
+ if (!this.foreignKey) {
7
+ this.foreignKey = `${inflection.underscore(this.getTargetModelClass().name)}_id`
8
+ }
9
+
10
+ return this.foreignKey
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import BaseRelationship from "./base.mjs"
2
+ import * as inflection from "inflection"
3
+
4
+ export default class VelociousDatabaseRecordHasManyRelationship extends BaseRelationship {
5
+ getForeignKey() {
6
+ if (!this.foreignKey) {
7
+ this.foreignKey = `${inflection.underscore(this.modelClass.name)}_id`
8
+ }
9
+
10
+ return this.foreignKey
11
+ }
12
+ }
@@ -33,18 +33,22 @@ export default class TableData {
33
33
  this._name = name
34
34
  }
35
35
 
36
+ _defineColumn(name, args = {}) {
37
+ const column = new TableColumn(name, args)
38
+
39
+ this._columns.push(column)
40
+ }
41
+
36
42
  getColumns = () => this._columns
37
43
  getName = () => this._name
38
44
  getIfNotExists = () => this.args.ifNotExists
39
45
  getIndexes = () => this._indexes
40
46
  getReferences = () => this._references
41
47
 
42
- bigint(name, args = {}) {
43
- const columnArgs = Object.assign({type: "bigint"}, args)
44
- const column = new TableColumn(name, columnArgs)
45
-
46
- this._columns.push(column)
47
- }
48
+ bigint = (name, args = {}) => this._defineColumn(name, Object.assign({type: "bigint"}, args))
49
+ boolean = (name, args) => this._defineColumn(name, Object.assign({type: "boolean"}, args))
50
+ datetime = (name, args) => this._defineColumn(name, Object.assign({type: "datetime"}, args))
51
+ integer = (name, args = {}) => this._defineColumn(name, Object.assign({type: "integer"}, args))
48
52
 
49
53
  references(name, args = {}) {
50
54
  const columnName = `${name}_id`
@@ -59,25 +63,11 @@ export default class TableData {
59
63
  this._references.push(reference)
60
64
  }
61
65
 
62
- string(name, args) {
63
- const columnArgs = Object.assign({type: "string"}, args)
64
- const column = new TableColumn(name, columnArgs)
65
-
66
- this._columns.push(column)
67
- }
68
-
69
- text(name, args) {
70
- const columnArgs = Object.assign({type: "text"}, args)
71
- const column = new TableColumn(name, columnArgs)
72
-
73
- this._columns.push(column)
74
- }
75
-
76
- timestamps() {
77
- const createdAtColumn = new TableColumn("created_at", {type: "datetime"})
78
- const updatedAtColumn = new TableColumn("updated_at", {type: "datetime"})
66
+ string = (name, args) => this._defineColumn(name, Object.assign({type: "string"}, args))
67
+ text = (name, args) => this._defineColumn(name, Object.assign({type: "text"}, args))
79
68
 
80
- this._columns.push(createdAtColumn)
81
- this._columns.push(updatedAtColumn)
69
+ timestamps(args = {}) {
70
+ this.datetime("created_at", args)
71
+ this.datetime("updated_at", args)
82
72
  }
83
73
  }
@@ -27,12 +27,15 @@ export default class VelociousHttpServerWorkerHandlerWorkerThread {
27
27
  const {debug, directory} = digs(this.workerData, "debug", "directory")
28
28
  const configurationPath = `${this.workerData.directory}/src/config/configuration.mjs`
29
29
  const configurationImport = await import(configurationPath)
30
- const configuration = configurationImport.default
31
30
 
32
- this.application = new Application({configuration, debug, directory})
33
-
34
- this.configuration = configuration
31
+ this.configuration = configurationImport.default
35
32
  this.configuration.setCurrent()
33
+
34
+ this.application = new Application({configuration: this.configuration, debug, directory})
35
+
36
+ if (this.configuration.isInitialized()) {
37
+ await this.configuration.initialize()
38
+ }
36
39
  }
37
40
 
38
41
  onCommand = (data) => {
@@ -1,4 +1,6 @@
1
1
  import Record from "velocious/src/database/record/index.mjs"
2
2
 
3
- export default class __MODEL_NAME__ extends Record {
3
+ class __MODEL_NAME__ extends Record {
4
4
  }
5
+
6
+ export default __MODEL_NAME__
@@ -0,0 +1,9 @@
1
+ const restArgsError = (restArgs) => {
2
+ const restArgsKeys = Object.keys(restArgs)
3
+
4
+ if (restArgsKeys.length > 0) {
5
+ throw new Error(`Unknown arguments: ${restArgsKeys.join(", ")}`)
6
+ }
7
+ }
8
+
9
+ export default restArgsError