velocious 1.0.1 → 1.0.3

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 (157) hide show
  1. package/README.md +36 -0
  2. package/bin/velocious.mjs +8 -0
  3. package/index.mjs +21 -0
  4. package/package.json +15 -7
  5. package/peak_flow.yml +12 -5
  6. package/spec/cli/commands/db/create-spec.mjs +25 -0
  7. package/spec/cli/commands/db/migrate-spec.mjs +37 -0
  8. package/spec/cli/commands/destroy/migration-spec.mjs +15 -0
  9. package/spec/cli/commands/generate/migration-spec.mjs +18 -0
  10. package/spec/cli/commands/init-spec.mjs +19 -0
  11. package/spec/cli/commands/test/test-files-finder-spec.mjs +12 -0
  12. package/spec/database/connection/drivers/mysql/{query-parser-spec.cjs → query-parser-spec.mjs} +12 -8
  13. package/spec/database/drivers/mysql/connection-spec.mjs +21 -0
  14. package/spec/database/record/create-spec.mjs +14 -0
  15. package/spec/database/record/destroy-spec.mjs +17 -0
  16. package/spec/database/record/find-spec.mjs +29 -0
  17. package/spec/database/record/update-spec.mjs +15 -0
  18. package/spec/dummy/dummy-directory.mjs +11 -0
  19. package/spec/dummy/index.mjs +63 -0
  20. package/spec/dummy/src/config/configuration.example.mjs +19 -0
  21. package/spec/dummy/src/config/configuration.peakflow.mjs +20 -0
  22. package/spec/dummy/src/{routes.cjs → config/routes.mjs} +3 -2
  23. package/spec/dummy/src/database/migrations/20230728075328-create-projects.mjs +11 -0
  24. package/spec/dummy/src/database/migrations/20230728075329-create-tasks.mjs +13 -0
  25. package/spec/dummy/src/models/task.mjs +4 -0
  26. package/spec/dummy/src/routes/tasks/controller.mjs +26 -0
  27. package/spec/http-server/{client-spec.cjs → client-spec.mjs} +7 -10
  28. package/spec/http-server/{get-spec.cjs → get-spec.mjs} +2 -2
  29. package/spec/http-server/post-spec.mjs +72 -0
  30. package/spec/support/jasmine.json +4 -3
  31. package/src/application.mjs +50 -0
  32. package/src/cli/base-command.mjs +11 -0
  33. package/src/cli/commands/db/create.mjs +50 -0
  34. package/src/cli/commands/db/migrate.mjs +58 -0
  35. package/src/cli/commands/destroy/migration.mjs +35 -0
  36. package/src/cli/commands/generate/migration.mjs +36 -0
  37. package/src/cli/commands/init.mjs +60 -0
  38. package/src/cli/commands/test/index.mjs +14 -0
  39. package/src/cli/commands/test/test-files-finder.mjs +99 -0
  40. package/src/cli/commands/test/test-runner.mjs +19 -0
  41. package/src/cli/index.mjs +59 -0
  42. package/src/configuration-resolver.mjs +26 -0
  43. package/src/configuration.mjs +49 -0
  44. package/src/{controller.cjs → controller.mjs} +21 -4
  45. package/src/database/drivers/base.mjs +17 -0
  46. package/src/database/drivers/index.mjs +5 -0
  47. package/src/database/drivers/mysql/connect-connection.mjs +12 -0
  48. package/src/database/drivers/mysql/index.mjs +102 -0
  49. package/src/database/drivers/mysql/options.mjs +17 -0
  50. package/src/database/drivers/mysql/query-parser.mjs +25 -0
  51. package/src/database/drivers/mysql/query.mjs +26 -0
  52. package/src/database/drivers/mysql/sql/create-database.mjs +4 -0
  53. package/src/database/drivers/mysql/sql/create-table.mjs +4 -0
  54. package/src/database/drivers/mysql/sql/delete.mjs +19 -0
  55. package/src/database/drivers/mysql/sql/insert.mjs +29 -0
  56. package/src/database/drivers/mysql/sql/update.mjs +31 -0
  57. package/src/database/drivers/sqlite/options.mjs +17 -0
  58. package/src/database/drivers/sqlite/query-parser.mjs +25 -0
  59. package/src/database/drivers/sqlite/sql/create-database.mjs +4 -0
  60. package/src/database/drivers/sqlite/sql/create-table.mjs +4 -0
  61. package/src/database/drivers/sqlite/sql/delete.mjs +19 -0
  62. package/src/database/drivers/sqlite/sql/insert.mjs +29 -0
  63. package/src/database/drivers/sqlite/sql/update.mjs +31 -0
  64. package/src/database/drivers/sqlite-expo/index.mjs +100 -0
  65. package/src/database/drivers/sqlite-expo/query.mjs +9 -0
  66. package/src/database/handler.mjs +7 -0
  67. package/src/database/index.mjs +15 -0
  68. package/src/database/migration/index.mjs +18 -0
  69. package/src/database/migrator/index.mjs +15 -0
  70. package/src/database/pool/index.mjs +112 -0
  71. package/src/database/query/base.mjs +11 -0
  72. package/src/database/query/create-database-base.mjs +20 -0
  73. package/src/database/query/create-table-base.mjs +69 -0
  74. package/src/database/query/delete-base.mjs +9 -0
  75. package/src/database/query/from-base.mjs +9 -0
  76. package/src/database/query/from-plain.mjs +10 -0
  77. package/src/database/query/from-table.mjs +12 -0
  78. package/src/database/query/index.mjs +144 -0
  79. package/src/database/query/insert-base.mjs +15 -0
  80. package/src/database/query/join-base.mjs +9 -0
  81. package/src/database/query/join-plain.mjs +12 -0
  82. package/src/database/query/order-base.mjs +9 -0
  83. package/src/database/query/order-plain.mjs +21 -0
  84. package/src/database/query/select-base.mjs +9 -0
  85. package/src/database/query/select-plain.mjs +12 -0
  86. package/src/database/query/{select-table-and-column.cjs → select-table-and-column.mjs} +4 -4
  87. package/src/database/query/update-base.mjs +16 -0
  88. package/src/database/query-parser/{from-parser.cjs → from-parser.mjs} +3 -6
  89. package/src/database/query-parser/{joins-parser.cjs → joins-parser.mjs} +3 -6
  90. package/src/database/query-parser/{options.cjs → options.mjs} +13 -2
  91. package/src/database/query-parser/{select-parser.cjs → select-parser.mjs} +7 -6
  92. package/src/database/record/index.mjs +187 -0
  93. package/src/database/record/record-not-found-error.mjs +1 -0
  94. package/src/database/table-data/index.mjs +83 -0
  95. package/src/{error-logger.js → error-logger.mjs} +1 -1
  96. package/src/http-server/client/{index.cjs → index.mjs} +10 -11
  97. package/src/http-server/client/params-to-object.mjs +68 -0
  98. package/src/http-server/client/request-buffer/form-data-part.mjs +42 -0
  99. package/src/http-server/client/request-buffer/header.mjs +7 -0
  100. package/src/http-server/client/request-buffer/index.mjs +229 -0
  101. package/src/http-server/client/request-parser.mjs +47 -0
  102. package/src/http-server/client/{request-runner.cjs → request-runner.mjs} +5 -5
  103. package/src/http-server/client/request.mjs +15 -0
  104. package/src/http-server/client/{response.cjs → response.mjs} +1 -1
  105. package/src/http-server/index.mjs +137 -0
  106. package/src/http-server/server-client.mjs +47 -0
  107. package/src/http-server/worker-handler/index.mjs +79 -0
  108. package/src/http-server/worker-handler/worker-script.mjs +4 -0
  109. package/src/http-server/worker-handler/worker-thread.mjs +65 -0
  110. package/src/{logger.cjs → logger.mjs} +2 -2
  111. package/src/routes/base-route.mjs +34 -0
  112. package/src/routes/{get-route.cjs → get-route.mjs} +5 -3
  113. package/src/routes/index.mjs +9 -0
  114. package/src/routes/{resolver.cjs → resolver.mjs} +17 -9
  115. package/src/routes/{resource-route.cjs → resource-route.mjs} +9 -5
  116. package/src/routes/root-route.mjs +6 -0
  117. package/src/spec/index.mjs +5 -0
  118. package/src/templates/configuration.mjs +17 -0
  119. package/src/templates/generate-migration.mjs +11 -0
  120. package/src/templates/routes.mjs +11 -0
  121. package/src/utils/file-exists.mjs +13 -0
  122. package/bin/velocious +0 -14
  123. package/index.cjs +0 -13
  124. package/spec/dummy/config/databases.example.json +0 -10
  125. package/spec/dummy/config/databases.json +0 -0
  126. package/spec/dummy/config/databases.peakflow.json +0 -11
  127. package/spec/dummy/index.cjs +0 -40
  128. package/spec/dummy/src/models/task.cjs +0 -4
  129. package/spec/dummy/src/routes/tasks/controller.cjs +0 -18
  130. package/src/application.cjs +0 -36
  131. package/src/configuration.cjs +0 -14
  132. package/src/database/connection/drivers/mysql/index.cjs +0 -5
  133. package/src/database/connection/drivers/mysql/options.cjs +0 -7
  134. package/src/database/connection/drivers/mysql/query-parser.cjs +0 -26
  135. package/src/database/connection/index.cjs +0 -2
  136. package/src/database/handler.cjs +0 -5
  137. package/src/database/index.cjs +0 -9
  138. package/src/database/pool/index.cjs +0 -2
  139. package/src/database/query/from-base.cjs +0 -15
  140. package/src/database/query/from-plain.cjs +0 -12
  141. package/src/database/query/from-table.cjs +0 -12
  142. package/src/database/query/index.cjs +0 -59
  143. package/src/database/query/join-base.cjs +0 -15
  144. package/src/database/query/join-plain.cjs +0 -12
  145. package/src/database/query/select-base.cjs +0 -15
  146. package/src/database/query/select-plain.cjs +0 -12
  147. package/src/database/record/index.cjs +0 -5
  148. package/src/http-server/client/request-parser.cjs +0 -92
  149. package/src/http-server/client/request.cjs +0 -25
  150. package/src/http-server/index.cjs +0 -78
  151. package/src/http-server/worker-handler/index.cjs +0 -78
  152. package/src/http-server/worker-handler/socket-handler.cjs +0 -35
  153. package/src/http-server/worker-handler/worker-script.cjs +0 -4
  154. package/src/http-server/worker-handler/worker-thread.cjs +0 -49
  155. package/src/routes/base-route.cjs +0 -25
  156. package/src/routes/index.cjs +0 -9
  157. package/src/routes/root-route.cjs +0 -4
@@ -0,0 +1,112 @@
1
+ import {AsyncLocalStorage} from "node:async_hooks"
2
+ import Configuration from "../../configuration.mjs"
3
+ import {digg} from "diggerize"
4
+
5
+ const asyncLocalStorage = new AsyncLocalStorage()
6
+ let idSeq = 0
7
+
8
+ class VelociousDatabasePool {
9
+ static current() {
10
+ if (!global.velociousDatabasePool) global.velociousDatabasePool = new VelociousDatabasePool()
11
+
12
+ return global.velociousDatabasePool
13
+ }
14
+
15
+ constructor(args = {}) {
16
+ this.configuration = args.configuration || Configuration.current()
17
+ this.connections = []
18
+ this.connectionsInUse = {}
19
+ }
20
+
21
+ checkin = (connection) => {
22
+ const id = connection.getIdSeq()
23
+
24
+ if (id in this.connectionsInUse) {
25
+ delete this.connectionsInUse[id]
26
+ }
27
+
28
+ connection.setIdSeq(undefined)
29
+
30
+ this.connections.push(connection)
31
+ }
32
+
33
+ async checkout() {
34
+ let connection = this.connections.shift()
35
+
36
+ if (!connection) {
37
+ connection = await this.spawnConnection()
38
+ }
39
+
40
+ if (connection.getIdSeq() !== undefined) throw new Error(`Connection already has an ID-seq - is it in use? ${connection.getIdSeq()}`)
41
+
42
+ const id = idSeq++
43
+
44
+ connection.setIdSeq(id)
45
+ this.connectionsInUse[id] = connection
46
+
47
+ return connection
48
+ }
49
+
50
+ getConfiguration = () => digg(this, "configuration", "database", "default", "master")
51
+
52
+ setCurrent() {
53
+ global.velociousDatabasePool = this
54
+ }
55
+
56
+ async spawnConnection() {
57
+ const defaultConfig = this.getConfiguration()
58
+ const connection = await this.spawnConnectionWithConfiguration(defaultConfig)
59
+
60
+ return connection
61
+ }
62
+
63
+ async spawnConnectionWithConfiguration(config) {
64
+ const driverPath = `../drivers/${digg(config, "type")}/index.mjs`
65
+ const DriverClassImport = await import(driverPath)
66
+ const DriverClass = DriverClassImport.default
67
+ const connection = new DriverClass(config)
68
+
69
+ await connection.connect()
70
+
71
+ return connection
72
+ }
73
+
74
+ async withConnection(callback) {
75
+ const connection = await this.checkout()
76
+ const id = connection.getIdSeq()
77
+
78
+ await asyncLocalStorage.run(id, async () => {
79
+ try {
80
+ await callback()
81
+ } finally {
82
+ this.checkin(connection)
83
+ }
84
+ })
85
+ }
86
+
87
+ getCurrentConnection() {
88
+ const id = asyncLocalStorage.getStore()
89
+
90
+ if (id === undefined) {
91
+ throw new Error("ID hasn't been set for this async context")
92
+ }
93
+
94
+ if (!(id in this.connectionsInUse)) {
95
+ throw new Error(`Connection ${id} doesn't exist any more - has it been checked in again?`)
96
+ }
97
+
98
+ return this.connectionsInUse[id]
99
+ }
100
+ }
101
+
102
+ const forwardMethods = ["createTableSql", "deleteSql", "insertSql", "query", "quote", "updateSql"]
103
+
104
+ for (const forwardMethod of forwardMethods) {
105
+ VelociousDatabasePool.prototype[forwardMethod] = function(...args) {
106
+ const connection = this.getCurrentConnection()
107
+
108
+ return connection[forwardMethod](...args)
109
+ }
110
+ }
111
+
112
+ export default VelociousDatabasePool
@@ -0,0 +1,11 @@
1
+ export default class VelociousDatabaseQueryBase {
2
+ constructor({driver}) {
3
+ this.driver = driver
4
+ }
5
+
6
+ getOptions = () => this.driver?.options()
7
+
8
+ toSql() {
9
+ throw new Error("'toSql' wasn't implemented")
10
+ }
11
+ }
@@ -0,0 +1,20 @@
1
+ import QueryBase from "./base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryCreateDatabaseBase extends QueryBase {
4
+ constructor({driver, databaseName, ifNotExists}) {
5
+ super({driver})
6
+ this.databaseName = databaseName
7
+ this.ifNotExists = ifNotExists
8
+ }
9
+
10
+ toSql() {
11
+ const {databaseName} = this
12
+ let sql = "CREATE DATABASE"
13
+
14
+ if (this.ifNotExists) sql += " IF NOT EXISTS"
15
+
16
+ sql += ` ${databaseName}`
17
+
18
+ return sql
19
+ }
20
+ }
@@ -0,0 +1,69 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ import QueryBase from "./base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryDeleteBase extends QueryBase {
4
+ constructor({conditions, driver, tableName}) {
5
+ super({driver})
6
+ this.conditions = conditions
7
+ this.tableName = tableName
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ export default class VelociousDatabaseQueryFromBase {
2
+ getOptions() {
3
+ return this.query.getOptions()
4
+ }
5
+
6
+ toSql() {
7
+ throw new Error("'toSql' wasn't implemented")
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ import FromBase from "./from-base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryFromPlain extends FromBase {
4
+ constructor({driver, plain}) {
5
+ super({driver})
6
+ this.plain = plain
7
+ }
8
+
9
+ toSql = () => this.plain
10
+ }
@@ -0,0 +1,12 @@
1
+ import FromBase from "./from-base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryFromTable extends FromBase {
4
+ constructor({driver, tableName}) {
5
+ super({driver})
6
+ this.tableName = tableName
7
+ }
8
+
9
+ toSql() {
10
+ return this.getOptions().quoteTableName(this.tableName)
11
+ }
12
+ }
@@ -0,0 +1,144 @@
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
+ }
@@ -0,0 +1,15 @@
1
+ export default class VelociousDatabaseQueryInsertBase {
2
+ constructor({driver, tableName, data}) {
3
+ this.data = data
4
+ this.driver = driver
5
+ this.tableName = tableName
6
+ }
7
+
8
+ getOptions() {
9
+ return this.driver.options()
10
+ }
11
+
12
+ toSql() {
13
+ throw new Error("'toSql' wasn't implemented")
14
+ }
15
+ }
@@ -0,0 +1,9 @@
1
+ export default class VelociousDatabaseQueryJoinBase {
2
+ getOptions() {
3
+ return this.query.driver.options()
4
+ }
5
+
6
+ toSql() {
7
+ throw new Error("'toSql' wasn't implemented")
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ import JoinBase from "./join-base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryJoinPlain extends JoinBase {
4
+ constructor({plain}) {
5
+ super()
6
+ this.plain = plain
7
+ }
8
+
9
+ toSql() {
10
+ return this.plain
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ export default class VelociousDatabaseQueryOrderBase {
2
+ getOptions() {
3
+ return this.query.driver.options()
4
+ }
5
+
6
+ toSql() {
7
+ throw new Error("'toSql' wasn't implemented")
8
+ }
9
+ }
@@ -0,0 +1,21 @@
1
+ import OrderBase from "./order-base.mjs"
2
+
3
+ export default class VelociousDatabaseQueryOrderPlain extends OrderBase {
4
+ constructor({plain}) {
5
+ super()
6
+ this.plain = plain
7
+ this.reverseOrder = false
8
+ }
9
+
10
+ setReverseOrder() {
11
+ this.reverseOrder = true
12
+ }
13
+
14
+ toSql() {
15
+ if (this.reverseOrder) {
16
+ return `${this.plain} DESC`
17
+ }
18
+
19
+ return this.plain
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ export default class VelociousDatabaseQuerySelectBase {
2
+ getOptions() {
3
+ return this.query.driver.options()
4
+ }
5
+
6
+ toSql() {
7
+ throw new Error("'toSql' wasn't implemented")
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ import SelectBase from "./select-base.mjs"
2
+
3
+ export default class VelociousDatabaseQuerySelectPlain extends SelectBase {
4
+ constructor({plain}) {
5
+ super()
6
+ this.plain = plain
7
+ }
8
+
9
+ toSql() {
10
+ return this.plain
11
+ }
12
+ }
@@ -1,8 +1,8 @@
1
- const SelectBase = require("./select-base.cjs")
1
+ import SelectBase from "./select-base.mjs"
2
2
 
3
- module.exports = class VelociousDatabaseQuerySelectTableAndColumn extends SelectBase {
4
- constructor({tableName, columnName}) {
5
- super()
3
+ export default class VelociousDatabaseQuerySelectTableAndColumn extends SelectBase {
4
+ constructor({query, tableName, columnName}) {
5
+ super({query})
6
6
  this.columnName = columnName
7
7
  this.tableName = tableName
8
8
  }
@@ -0,0 +1,16 @@
1
+ export default class VelociousDatabaseQueryUpdateBase {
2
+ constructor({conditions, data, driver, tableName}) {
3
+ this.conditions = conditions
4
+ this.data = data
5
+ this.driver = driver
6
+ this.tableName = tableName
7
+ }
8
+
9
+ getOptions() {
10
+ return this.driver.options()
11
+ }
12
+
13
+ toSql() {
14
+ throw new Error("'toSql' wasn't implemented")
15
+ }
16
+ }
@@ -1,10 +1,9 @@
1
- const {digs} = require("diggerize")
1
+ import {digs} from "diggerize"
2
2
 
3
- module.exports = class VelociousDatabaseQueryParserFromParser {
4
- constructor({pretty, query, queryParserOptions}) {
3
+ export default class VelociousDatabaseQueryParserFromParser {
4
+ constructor({pretty, query}) {
5
5
  this.pretty = pretty
6
6
  this.query = query
7
- this.queryParserOptions = queryParserOptions
8
7
  }
9
8
 
10
9
  toSql() {
@@ -15,8 +14,6 @@ module.exports = class VelociousDatabaseQueryParserFromParser {
15
14
  for (const fromKey in query._froms) {
16
15
  const from = query._froms[fromKey]
17
16
 
18
- from.setOptions(this.queryParserOptions)
19
-
20
17
  if (fromKey > 0) {
21
18
  sql += ","
22
19
  }
@@ -1,10 +1,9 @@
1
- const {digs} = require("diggerize")
1
+ import {digs} from "diggerize"
2
2
 
3
- module.exports = class VelocuiousDatabaseQueryParserJoinsParser {
4
- constructor({pretty, query, queryParserOptions}) {
3
+ export default class VelocuiousDatabaseQueryParserJoinsParser {
4
+ constructor({pretty, query}) {
5
5
  this.pretty = pretty
6
6
  this.query = query
7
- this.queryParserOptions = queryParserOptions
8
7
  }
9
8
 
10
9
  toSql() {
@@ -15,8 +14,6 @@ module.exports = class VelocuiousDatabaseQueryParserJoinsParser {
15
14
  for (const joinKey in query._joins) {
16
15
  const join = query._joins[joinKey]
17
16
 
18
- join.setOptions(this.queryParserOptions)
19
-
20
17
  if (joinKey == 0) {
21
18
  if (pretty) {
22
19
  sql += "\n\n"
@@ -1,9 +1,13 @@
1
- const {digg} = require("diggerize")
1
+ import {digg} from "diggerize"
2
2
 
3
- module.exports = class VelociousDatabaseQueryParserOptions {
3
+ export default class VelociousDatabaseQueryParserOptions {
4
4
  constructor(options) {
5
5
  this.columnQuote = digg(options, "columnQuote")
6
+ this.driver = digg(options, "driver")
6
7
  this.tableQuote = digg(options, "tableQuote")
8
+ this.stringQuote = digg(options, "stringQuote")
9
+
10
+ if (!this.driver) throw new Error("No driver given")
7
11
  }
8
12
 
9
13
  quoteColumnName(columnName) {
@@ -17,4 +21,11 @@ module.exports = class VelociousDatabaseQueryParserOptions {
17
21
 
18
22
  return `${this.tableQuote}${tableName}${this.tableQuote}`
19
23
  }
24
+
25
+ quote(value) {
26
+ if (typeof value == "number")
27
+ return value
28
+
29
+ return this.quoteString(value)
30
+ }
20
31
  }
@@ -1,10 +1,9 @@
1
- const {digs} = require("diggerize")
1
+ import {digs} from "diggerize"
2
2
 
3
- module.exports = class VelociousDatabaseQueryParserSelectParser {
4
- constructor({pretty, query, queryParserOptions}) {
3
+ export default class VelociousDatabaseQueryParserSelectParser {
4
+ constructor({pretty, query}) {
5
5
  this.pretty = pretty
6
6
  this.query = query
7
- this.queryParserOptions = queryParserOptions
8
7
  }
9
8
 
10
9
  toSql() {
@@ -23,8 +22,6 @@ module.exports = class VelociousDatabaseQueryParserSelectParser {
23
22
  for (const selectKey in query._selects) {
24
23
  const selectValue = query._selects[selectKey]
25
24
 
26
- selectValue.setOptions(this.queryParserOptions)
27
-
28
25
  sql += selectValue.toSql()
29
26
 
30
27
  if (selectKey + 1 < query._selects.length) {
@@ -37,6 +34,10 @@ module.exports = class VelociousDatabaseQueryParserSelectParser {
37
34
  }
38
35
  }
39
36
 
37
+ if (query._selects.length == 0) {
38
+ sql += "*"
39
+ }
40
+
40
41
  return sql
41
42
  }
42
43
  }