velocious 1.0.5 → 1.0.7

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 (173) hide show
  1. package/bin/{velocious.mjs → velocious.js} +1 -1
  2. package/package.json +7 -5
  3. package/peak_flow.yml +1 -1
  4. package/spec/cli/commands/db/{create-spec.mjs → create-spec.js} +3 -3
  5. package/spec/cli/commands/db/{migrate-spec.mjs → migrate-spec.js} +4 -2
  6. package/spec/cli/commands/destroy/{migration-spec.mjs → migration-spec.js} +2 -2
  7. package/spec/cli/commands/generate/{migration-spec.mjs → migration-spec.js} +3 -3
  8. package/spec/cli/commands/{init-spec.mjs → init-spec.js} +6 -6
  9. package/spec/cli/commands/test/{test-files-finder-spec.mjs → test-files-finder-spec.js} +2 -2
  10. package/spec/database/connection/drivers/mysql/{query-parser-spec.mjs → query-parser-spec.js} +6 -6
  11. package/spec/database/drivers/mysql/{connection-spec.mjs → connection-spec.js} +2 -2
  12. package/spec/database/record/create-spec.js +23 -0
  13. package/spec/database/record/{destroy-spec.mjs → destroy-spec.js} +2 -2
  14. package/spec/database/record/{find-spec.mjs → find-spec.js} +2 -3
  15. package/spec/database/record/query-spec.js +37 -0
  16. package/spec/database/record/{update-spec.mjs → update-spec.js} +2 -2
  17. package/spec/dummy/{index.mjs → index.js} +16 -4
  18. package/spec/dummy/src/config/configuration.example.js +36 -0
  19. package/spec/dummy/src/config/configuration.peakflow.js +37 -0
  20. package/spec/dummy/src/config/{routes.mjs → routes.js} +1 -1
  21. package/spec/dummy/src/database/migrations/{20230728075328-create-projects.mjs → 20230728075328-create-projects.js} +1 -2
  22. package/spec/dummy/src/database/migrations/{20230728075329-create-tasks.mjs → 20230728075329-create-tasks.js} +1 -2
  23. package/spec/dummy/src/database/migrations/20250605133926-create-project-translations.js +16 -0
  24. package/spec/dummy/src/models/project.js +9 -0
  25. package/spec/dummy/src/models/task.js +8 -0
  26. package/spec/dummy/src/routes/tasks/{controller.mjs → controller.js} +2 -2
  27. package/spec/http-server/{client-spec.mjs → client-spec.js} +3 -3
  28. package/spec/http-server/{get-spec.mjs → get-spec.js} +1 -1
  29. package/spec/http-server/{post-spec.mjs → post-spec.js} +2 -2
  30. package/spec/support/jasmine.json +2 -2
  31. package/src/{application.mjs → application.js} +3 -3
  32. package/src/big-brother.js +37 -0
  33. package/src/cli/commands/db/{create.mjs → create.js} +9 -7
  34. package/src/cli/commands/db/{migrate.mjs → migrate.js} +4 -5
  35. package/src/cli/commands/destroy/{migration.mjs → migration.js} +2 -2
  36. package/src/cli/commands/generate/{migration.mjs → migration.js} +5 -5
  37. package/src/cli/commands/generate/{model.mjs → model.js} +5 -5
  38. package/src/cli/commands/{init.mjs → init.js} +6 -6
  39. package/src/cli/commands/{server.mjs → server.js} +1 -1
  40. package/src/cli/commands/test/{index.mjs → index.js} +3 -3
  41. package/src/cli/commands/test/{test-files-finder.mjs → test-files-finder.js} +1 -1
  42. package/src/cli/{index.mjs → index.js} +4 -4
  43. package/src/{configuration-resolver.mjs → configuration-resolver.js} +2 -2
  44. package/src/{configuration.mjs → configuration.js} +39 -3
  45. package/src/database/drivers/{base.mjs → base.js} +23 -4
  46. package/src/database/drivers/mysql/column.js +8 -0
  47. package/src/database/drivers/mysql/{index.mjs → index.js} +44 -12
  48. package/src/database/drivers/{sqlite/options.mjs → mysql/options.js} +2 -1
  49. package/src/database/drivers/mysql/query-parser.js +4 -0
  50. package/src/database/drivers/mysql/sql/{create-database.mjs → create-database.js} +1 -1
  51. package/src/database/drivers/{sqlite/sql/create-table.mjs → mysql/sql/create-table.js} +1 -1
  52. package/src/database/drivers/mysql/sql/{delete.mjs → delete.js} +1 -1
  53. package/src/database/drivers/{sqlite/sql/insert.mjs → mysql/sql/insert.js} +1 -1
  54. package/src/database/drivers/mysql/sql/{update.mjs → update.js} +1 -1
  55. package/src/database/drivers/mysql/table.js +25 -0
  56. package/src/database/drivers/sqlite/base.js +108 -0
  57. package/src/database/drivers/sqlite/column.js +10 -0
  58. package/src/database/drivers/sqlite/{index.native.mjs → index.native.js} +19 -22
  59. package/src/database/drivers/sqlite/index.web.js +55 -0
  60. package/src/database/drivers/{mysql/options.mjs → sqlite/options.js} +3 -2
  61. package/src/database/drivers/sqlite/query-parser.js +4 -0
  62. package/src/database/drivers/sqlite/query.native.js +24 -0
  63. package/src/database/drivers/sqlite/query.web.js +34 -0
  64. package/src/database/drivers/sqlite/sql/create-index.js +4 -0
  65. package/src/database/drivers/{mysql/sql/create-table.mjs → sqlite/sql/create-table.js} +1 -1
  66. package/src/database/drivers/sqlite/sql/{delete.mjs → delete.js} +1 -1
  67. package/src/database/drivers/{mysql/sql/insert.mjs → sqlite/sql/insert.js} +1 -1
  68. package/src/database/drivers/sqlite/sql/{update.mjs → update.js} +1 -1
  69. package/src/database/drivers/sqlite/table.js +24 -0
  70. package/src/database/initializer-from-require-context.js +21 -0
  71. package/src/database/{migrate-from-require-context.mjs → migrate-from-require-context.js} +2 -2
  72. package/src/database/migration/index.js +50 -0
  73. package/src/database/{migrator.mjs → migrator.js} +4 -2
  74. package/src/database/pool/{async-tracked-multi-connection.mjs → async-tracked-multi-connection.js} +1 -1
  75. package/src/database/pool/{base.mjs → base.js} +6 -1
  76. package/src/database/pool/{single-multi-use.mjs → single-multi-use.js} +1 -1
  77. package/src/database/query/{base.mjs → base.js} +2 -1
  78. package/src/database/query/{create-database-base.mjs → create-database-base.js} +1 -1
  79. package/src/database/query/create-index-base.js +50 -0
  80. package/src/database/query/create-table-base.js +92 -0
  81. package/src/database/query/{delete-base.mjs → delete-base.js} +1 -1
  82. package/src/database/query/{from-plain.mjs → from-plain.js} +1 -1
  83. package/src/database/query/{from-table.mjs → from-table.js} +1 -1
  84. package/src/database/query/index.js +206 -0
  85. package/src/database/query/{join-plain.mjs → join-plain.js} +1 -1
  86. package/src/database/query/{order-plain.mjs → order-plain.js} +1 -1
  87. package/src/database/query/preloader/belongs-to.js +52 -0
  88. package/src/database/query/preloader/has-many.js +55 -0
  89. package/src/database/query/preloader.js +41 -0
  90. package/src/database/query/{select-plain.mjs → select-plain.js} +1 -1
  91. package/src/database/query/{select-table-and-column.mjs → select-table-and-column.js} +1 -1
  92. package/src/database/query/where-base.js +9 -0
  93. package/src/database/query/where-hash.js +35 -0
  94. package/src/database/query/where-plain.js +13 -0
  95. package/src/database/query-parser/base-query-parser.js +33 -0
  96. package/src/database/query-parser/group-parser.js +40 -0
  97. package/src/database/query-parser/joins-parser.js +71 -0
  98. package/src/database/query-parser/limit-parser.js +40 -0
  99. package/src/database/query-parser/{options.mjs → options.js} +2 -1
  100. package/src/database/query-parser/order-parser.js +39 -0
  101. package/src/database/query-parser/{select-parser.mjs → select-parser.js} +5 -1
  102. package/src/database/query-parser/where-parser.js +39 -0
  103. package/src/database/record/index.js +622 -0
  104. package/src/database/record/instance-relationships/base.js +28 -0
  105. package/src/database/record/instance-relationships/belongs-to.js +20 -0
  106. package/src/database/record/instance-relationships/has-many.js +47 -0
  107. package/src/database/record/relationships/base.js +32 -0
  108. package/src/database/record/relationships/belongs-to.js +12 -0
  109. package/src/database/record/relationships/has-many.js +12 -0
  110. package/src/database/table-data/{index.mjs → index.js} +15 -25
  111. package/src/http-server/client/{index.mjs → index.js} +3 -3
  112. package/src/http-server/client/request-buffer/{index.mjs → index.js} +4 -4
  113. package/src/http-server/client/{request-parser.mjs → request-parser.js} +2 -2
  114. package/src/http-server/client/{request-runner.mjs → request-runner.js} +3 -3
  115. package/src/http-server/client/{request.mjs → request.js} +1 -1
  116. package/src/http-server/{index.mjs → index.js} +3 -3
  117. package/src/http-server/{server-client.mjs → server-client.js} +1 -1
  118. package/src/http-server/worker-handler/{index.mjs → index.js} +2 -2
  119. package/src/http-server/worker-handler/{worker-script.mjs → worker-script.js} +1 -1
  120. package/src/http-server/worker-handler/{worker-thread.mjs → worker-thread.js} +12 -9
  121. package/src/routes/{app-routes.mjs → app-routes.js} +1 -1
  122. package/src/routes/{base-route.mjs → base-route.js} +2 -2
  123. package/src/routes/{get-route.mjs → get-route.js} +1 -1
  124. package/src/routes/{index.mjs → index.js} +1 -1
  125. package/src/routes/{resolver.mjs → resolver.js} +1 -1
  126. package/src/routes/{resource-route.mjs → resource-route.js} +1 -1
  127. package/src/routes/{root-route.mjs → root-route.js} +1 -1
  128. package/src/templates/{configuration.mjs → configuration.js} +3 -3
  129. package/src/templates/{generate-migration.mjs → generate-migration.js} +1 -1
  130. package/src/templates/generate-model.js +6 -0
  131. package/src/templates/{routes.mjs → routes.js} +1 -1
  132. package/src/utils/rest-args-error.js +9 -0
  133. package/spec/database/record/create-spec.mjs +0 -14
  134. package/spec/dummy/src/config/configuration.example.mjs +0 -21
  135. package/spec/dummy/src/config/configuration.peakflow.mjs +0 -22
  136. package/spec/dummy/src/models/task.mjs +0 -4
  137. package/src/database/drivers/mysql/query-parser.mjs +0 -25
  138. package/src/database/drivers/sqlite/base.mjs +0 -36
  139. package/src/database/drivers/sqlite/index.web.mjs +0 -45
  140. package/src/database/drivers/sqlite/query-parser.mjs +0 -25
  141. package/src/database/drivers/sqlite/query.native.mjs +0 -9
  142. package/src/database/drivers/sqlite/query.web.mjs +0 -9
  143. package/src/database/drivers/sqlite/table.mjs +0 -9
  144. package/src/database/migration/index.mjs +0 -18
  145. package/src/database/query/create-table-base.mjs +0 -69
  146. package/src/database/query/index.mjs +0 -144
  147. package/src/database/query-parser/joins-parser.mjs +0 -30
  148. package/src/database/record/index.mjs +0 -187
  149. package/src/templates/generate-model.mjs +0 -4
  150. /package/{index.mjs → index.js} +0 -0
  151. /package/spec/dummy/{dummy-directory.mjs → dummy-directory.js} +0 -0
  152. /package/src/cli/{base-command.mjs → base-command.js} +0 -0
  153. /package/src/cli/commands/test/{test-runner.mjs → test-runner.js} +0 -0
  154. /package/src/{controller.mjs → controller.js} +0 -0
  155. /package/src/database/drivers/mysql/{connect-connection.mjs → connect-connection.js} +0 -0
  156. /package/src/database/drivers/mysql/{query.mjs → query.js} +0 -0
  157. /package/src/database/{handler.mjs → handler.js} +0 -0
  158. /package/src/database/query/{from-base.mjs → from-base.js} +0 -0
  159. /package/src/database/query/{insert-base.mjs → insert-base.js} +0 -0
  160. /package/src/database/query/{join-base.mjs → join-base.js} +0 -0
  161. /package/src/database/query/{order-base.mjs → order-base.js} +0 -0
  162. /package/src/database/query/{select-base.mjs → select-base.js} +0 -0
  163. /package/src/database/query/{update-base.mjs → update-base.js} +0 -0
  164. /package/src/database/query-parser/{from-parser.mjs → from-parser.js} +0 -0
  165. /package/src/database/record/{record-not-found-error.mjs → record-not-found-error.js} +0 -0
  166. /package/src/{error-logger.mjs → error-logger.js} +0 -0
  167. /package/src/http-server/client/{params-to-object.mjs → params-to-object.js} +0 -0
  168. /package/src/http-server/client/request-buffer/{form-data-part.mjs → form-data-part.js} +0 -0
  169. /package/src/http-server/client/request-buffer/{header.mjs → header.js} +0 -0
  170. /package/src/http-server/client/{response.mjs → response.js} +0 -0
  171. /package/src/{logger.mjs → logger.js} +0 -0
  172. /package/src/spec/{index.mjs → index.js} +0 -0
  173. /package/src/utils/{file-exists.mjs → file-exists.js} +0 -0
@@ -1,9 +0,0 @@
1
- export default async function query(connection, sql) {
2
- const rows = []
3
-
4
- for await (const entry of connection.exec(sql)) {
5
- rows.push(entry)
6
- }
7
-
8
- return rows
9
- }
@@ -1,9 +0,0 @@
1
- import {digg} from "diggerize"
2
-
3
- export default class VelociousDatabaseDriversSqliteTable {
4
- constructor(row) {
5
- this.row = row
6
- }
7
-
8
- getName = () => digg(this, "row", "name")
9
- }
@@ -1,18 +0,0 @@
1
- import TableData from "../table-data/index.mjs"
2
-
3
- export default class VelociousDatabaseMigration {
4
- constructor({configuration}) {
5
- this.configuration = configuration
6
- }
7
-
8
- async createTable(tableName, callback) {
9
- const tableData = new TableData(tableName)
10
-
11
- callback(tableData)
12
-
13
- const databasePool = this.configuration.getDatabasePool()
14
- const sql = databasePool.createTableSql(tableData)
15
-
16
- await databasePool.query(sql)
17
- }
18
- }
@@ -1,69 +0,0 @@
1
- import QueryBase from "./base.mjs"
2
-
3
- export default class VelociousDatabaseQueryCreateTableBase extends QueryBase {
4
- constructor({driver, ifNotExists, tableData}) {
5
- super({driver})
6
- this.ifNotExists = ifNotExists
7
- this.tableData = tableData
8
- }
9
-
10
- toSql() {
11
- const {tableData} = this
12
- let sql = "CREATE TABLE"
13
-
14
- if (this.ifNotExists || tableData.getIfNotExists()) sql += " IF NOT EXISTS"
15
-
16
- sql += ` ${tableData.getName()} (`
17
-
18
- let columnCount = 0
19
-
20
- for (const column of tableData.getColumns()) {
21
- columnCount++
22
-
23
- let maxlength = column.args.maxlength
24
- let type = column.args.type
25
-
26
- if (type == "string") {
27
- type = "varchar"
28
- maxlength ||= 255
29
- }
30
-
31
- if (columnCount > 1) sql += ", "
32
-
33
- sql += `${this.driver.quoteColumn(column.name)} ${type}`
34
-
35
- if (maxlength !== undefined) sql += `(${maxlength})`
36
-
37
- if (column.args.autoIncrement) sql += " AUTO_INCREMENT"
38
- if (column.args.primaryKey) sql += " PRIMARY KEY"
39
- }
40
-
41
- for (const index of tableData.getIndexes()) {
42
- sql += ","
43
-
44
- if (index.getUnique()) {
45
- sql += " UNIQUE"
46
- }
47
-
48
- sql += " INDEX"
49
-
50
- if (index.getName()) {
51
- sql += ` ${index.getName()}`
52
- }
53
-
54
- sql += " ("
55
-
56
- index.getColumns().forEach((column, columnIndex) => {
57
- if (columnIndex > 0) sql += ", "
58
-
59
- sql += this.driver.quoteColumn(column.name)
60
- })
61
-
62
- sql += ")"
63
- }
64
-
65
- sql += ")"
66
-
67
- return sql
68
- }
69
- }
@@ -1,144 +0,0 @@
1
- import FromPlain from "./from-plain.mjs"
2
- import JoinPlain from "./join-plain.mjs"
3
- import OrderPlain from "./order-plain.mjs"
4
- import SelectPlain from "./select-plain.mjs"
5
-
6
- export default class VelociousDatabaseQuery {
7
- constructor({driver, froms = [], joins = [], handler, limits = [], modelClass, orders = [], selects = [], wheres = []}) {
8
- if (!driver) throw new Error("No driver given")
9
- if (!handler) throw new Error("No handler given")
10
-
11
- this.driver = driver
12
- this.handler = handler
13
- this.modelClass = modelClass
14
- this._froms = froms
15
- this._joins = joins
16
- this._limits = limits
17
- this._orders = orders
18
- this._selects = selects
19
- this._wheres = wheres
20
- }
21
-
22
- clone() {
23
- const newQuery = new VelociousDatabaseQuery({
24
- driver: this.driver,
25
- froms: [...this._froms],
26
- handler: this.handler.clone(),
27
- joins: [...this._joins],
28
- limits: [...this._limits],
29
- modelClass: this.modelClass,
30
- orders: [...this._orders],
31
- selects: [...this._selects],
32
- wheres: [...this._wheres]
33
- })
34
-
35
- return newQuery
36
- }
37
-
38
- getOptions() {
39
- return this.driver.options()
40
- }
41
-
42
- async first() {
43
- const newQuery = this.clone()
44
- const results = await newQuery.limit(1).reorder(this.modelClass.orderableColumn()).toArray()
45
-
46
- return results[0]
47
- }
48
-
49
- from(from) {
50
- if (typeof from == "string") from = new FromPlain({plain: from, query: this})
51
-
52
- from.query = this
53
-
54
- this._froms.push(from)
55
- return this
56
- }
57
-
58
- async last() {
59
- return await this.clone().reverseOrder().first()
60
- }
61
-
62
- limit(value) {
63
- this._limits.push(value)
64
- return this
65
- }
66
-
67
- joins(join) {
68
- if (typeof join == "string") join = new JoinPlain({plain: join, query: this})
69
-
70
- join.query = this
71
-
72
- this._joins.push(join)
73
- return this
74
- }
75
-
76
- order(order) {
77
- if (typeof order == "number" || typeof order == "string") order = new OrderPlain({plain: order, query: this})
78
-
79
- order.query = this
80
-
81
- this._orders.push(order)
82
- return this
83
- }
84
-
85
- reorder(order) {
86
- this._orders = []
87
- this.order(order)
88
- return this
89
- }
90
-
91
- reverseOrder() {
92
- for (const order of this._orders) {
93
- order.setReverseOrder(true)
94
- }
95
-
96
- return this
97
- }
98
-
99
- select(select) {
100
- if (Array.isArray(select)) {
101
- for (const selectInArray of select) {
102
- this.select(selectInArray)
103
- }
104
-
105
- return this
106
- }
107
-
108
- if (typeof select == "string") select = new SelectPlain({plain: select})
109
-
110
- select.query = this
111
-
112
- this._selects.push(select)
113
- return this
114
- }
115
-
116
- async toArray() {
117
- const sql = this.toSql()
118
- const results = await this.driver.query(sql)
119
- const models = []
120
-
121
- for (const result of results) {
122
- const model = new this.modelClass(result)
123
-
124
- models.push(model)
125
- }
126
-
127
- return models
128
- }
129
-
130
- toSql() {
131
- return this.driver.queryToSql(this)
132
- }
133
-
134
- where(where) {
135
- if (typeof where == "string") {
136
- where = new WherePlain({plain: where})
137
- } else if (typeof where == "object" && where.constructor.name == "object") {
138
- where = new WhereHash({hash: where})
139
- }
140
-
141
- this._wheres.push(where)
142
- return this
143
- }
144
- }
@@ -1,30 +0,0 @@
1
- import {digs} from "diggerize"
2
-
3
- export default class VelocuiousDatabaseQueryParserJoinsParser {
4
- constructor({pretty, query}) {
5
- this.pretty = pretty
6
- this.query = query
7
- }
8
-
9
- toSql() {
10
- const {pretty, query} = digs(this, "pretty", "query")
11
-
12
- let sql = ""
13
-
14
- for (const joinKey in query._joins) {
15
- const join = query._joins[joinKey]
16
-
17
- if (joinKey == 0) {
18
- if (pretty) {
19
- sql += "\n\n"
20
- } else {
21
- sql += " "
22
- }
23
- }
24
-
25
- sql += join.toSql()
26
- }
27
-
28
- return sql
29
- }
30
- }
@@ -1,187 +0,0 @@
1
- import Configuration from "../../configuration.mjs"
2
- import Handler from "../handler.mjs"
3
- import inflection from "inflection"
4
- import Query from "../query/index.mjs"
5
- import RecordNotFoundError from "./record-not-found-error.mjs"
6
-
7
- export default class VelociousDatabaseRecord {
8
- static connection() {
9
- const connection = Configuration.current().getDatabasePoolType().current().getCurrentConnection()
10
-
11
- if (!connection) throw new Error("No connection?")
12
-
13
- return connection
14
- }
15
-
16
- static async find(recordId) {
17
- const conditions = {}
18
-
19
- conditions[this.primaryKey()] = recordId
20
-
21
- const record = await this.where(conditions).first()
22
-
23
- if (!record) {
24
- throw new RecordNotFoundError(`Couldn't find ${this.name} with '${this.primaryKey()}'=${recordId}`)
25
- }
26
-
27
- return record
28
- }
29
-
30
- static async last() {
31
- const query = this._newQuery().order(this.primaryKey()).limit(1)
32
- const record = await query.last()
33
-
34
- return record
35
- }
36
-
37
- static primaryKey() {
38
- return "id"
39
- }
40
-
41
- async save() {
42
- if (this.isPersisted()) {
43
- return await this._updateRecordWithChanges()
44
- } else {
45
- return await this._createNewRecord()
46
- }
47
- }
48
-
49
- static tableName() {
50
- return inflection.underscore(inflection.pluralize(this.name))
51
- }
52
-
53
- static _newQuery() {
54
- const handler = new Handler()
55
- const query = new Query({
56
- driver: this.connection(),
57
- handler,
58
- modelClass: this
59
- })
60
-
61
- return query.from(this.tableName())
62
- }
63
-
64
- static orderableColumn() {
65
- // Allow to change to 'created_at' if using UUID?
66
-
67
- return this.primaryKey()
68
- }
69
-
70
- static where(object) {
71
- const query = this._newQuery().where(object)
72
-
73
- return query
74
- }
75
-
76
- constructor(attributes = {}) {
77
- this._attributes = attributes
78
- this._changes = {}
79
- }
80
-
81
- assign(attributesToAssign) {
82
- for (const attributeToAssign in attributesToAssign) {
83
- this._changes[attributeToAssign] = attributesToAssign[attributeToAssign]
84
- }
85
- }
86
-
87
- attributes() {
88
- return Object.assign({}, this._attributes, this._changes)
89
- }
90
-
91
- _connection() {
92
- if (this.__connection) return this.__connection
93
-
94
- return this.constructor.connection()
95
- }
96
-
97
- async destroy() {
98
- const conditions = {}
99
-
100
- conditions[this.constructor.primaryKey()] = this.id()
101
-
102
- const sql = this._connection().deleteSql({
103
- conditions,
104
- tableName: this._tableName()
105
- })
106
-
107
- await this._connection().query(sql)
108
- }
109
-
110
- _tableName() {
111
- if (this.__tableName) return this.__tableName
112
-
113
- return this.constructor.tableName()
114
- }
115
-
116
- readAttribute(attributeName) {
117
- if (attributeName in this._changes) return this._changes[attributeName]
118
-
119
- return this._attributes[attributeName]
120
- }
121
-
122
- async _createNewRecord() {
123
- if (!this.constructor.connection()["insertSql"]) {
124
- throw new Error(`No insertSql on ${this.constructor.connection().constructor.name}`)
125
- }
126
-
127
- const sql = this._connection().insertSql({
128
- tableName: this._tableName(),
129
- data: this.attributes()
130
- })
131
- const result = await this._connection().query(sql)
132
- const id = result.insertId
133
-
134
- await this._reloadWithId(id)
135
- }
136
-
137
- async _updateRecordWithChanges() {
138
- const conditions = {}
139
-
140
- conditions[this.constructor.primaryKey()] = this.id()
141
-
142
- const sql = this._connection().updateSql({
143
- tableName: this._tableName(),
144
- data: this._changes,
145
- conditions
146
- })
147
- await this._connection().query(sql)
148
- await this._reloadWithId(this.id())
149
- }
150
-
151
- id() {
152
- return this.readAttribute(this.constructor.primaryKey())
153
- }
154
-
155
- isPersisted() {
156
- if (this.id()) return true
157
-
158
- return false
159
- }
160
-
161
- isNewRecord() {
162
- return !this.isPersisted()
163
- }
164
-
165
- async _reloadWithId(id) {
166
- const primaryKey = this.constructor.primaryKey()
167
- const whereObject = {}
168
-
169
- whereObject[primaryKey] = id
170
-
171
- const query = this.constructor.where(whereObject)
172
- const reloadedModel = await query.first()
173
-
174
- this._attributes = reloadedModel.attributes()
175
- this._changes = {}
176
- }
177
-
178
- async reload() {
179
- this._reloadWithId(this.readAttribute("id"))
180
- }
181
-
182
- async update(attributesToAssign) {
183
- if (attributesToAssign) this.assign(attributesToAssign)
184
-
185
- await this.save()
186
- }
187
- }
@@ -1,4 +0,0 @@
1
- import Record from "velocious/src/database/record/index.mjs"
2
-
3
- export default class __MODEL_NAME__ extends Record {
4
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes