velocious 1.0.50 → 1.0.51
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 +13 -13
- package/src/database/drivers/sqlite/base.js +28 -7
- package/src/database/drivers/sqlite/index.js +1 -3
- package/src/database/drivers/sqlite/index.native.js +1 -3
- package/src/database/drivers/sqlite/index.web.js +1 -1
- package/src/database/drivers/sqlite/query.native.js +2 -1
- package/src/database/query/index.js +1 -1
- package/src/logger.js +10 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"velocious": "bin/velocious.js"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.51",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
|
|
@@ -21,19 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/kaspernj/velocious#readme",
|
|
23
23
|
"description": "",
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"awaitery": "^1.0.1",
|
|
26
|
-
"mssql": "^11.0.1",
|
|
27
|
-
"mysql": "^2.18.1",
|
|
28
|
-
"node-fetch": "^3.3.1",
|
|
29
|
-
"pg": "^8.16.3",
|
|
30
|
-
"require-context": "^1.1.0",
|
|
31
|
-
"sqlite": "^5.1.1",
|
|
32
|
-
"sqlite3": "^5.1.7",
|
|
33
|
-
"tedious": "^18.6.1",
|
|
34
|
-
"uniqunize": "^1.0.1"
|
|
35
|
-
},
|
|
36
24
|
"dependencies": {
|
|
25
|
+
"awaitery": "^1.0.1",
|
|
37
26
|
"bcryptjs": "^3.0.2",
|
|
38
27
|
"better-localstorage": "^1.0.7",
|
|
39
28
|
"debounce": "^2.2.0",
|
|
@@ -48,5 +37,16 @@
|
|
|
48
37
|
"sql-escape-string": "^1.1.0",
|
|
49
38
|
"sql.js": "^1.12.0",
|
|
50
39
|
"strftime": "^0.10.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"mssql": "^11.0.1",
|
|
43
|
+
"mysql": "^2.18.1",
|
|
44
|
+
"node-fetch": "^3.3.1",
|
|
45
|
+
"pg": "^8.16.3",
|
|
46
|
+
"require-context": "^1.1.0",
|
|
47
|
+
"sqlite": "^5.1.1",
|
|
48
|
+
"sqlite3": "^5.1.7",
|
|
49
|
+
"tedious": "^18.6.1",
|
|
50
|
+
"uniqunize": "^1.0.1"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -12,6 +12,7 @@ import Options from "./options.js"
|
|
|
12
12
|
import QueryParser from "./query-parser.js"
|
|
13
13
|
import Table from "./table.js"
|
|
14
14
|
import Update from "./sql/update.js"
|
|
15
|
+
import wait from "awaitery/src/wait.js"
|
|
15
16
|
|
|
16
17
|
export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
17
18
|
async alterTableSql(tableData) {
|
|
@@ -54,9 +55,9 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
54
55
|
return dropTable.toSql()
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
deleteSql
|
|
58
|
-
getType
|
|
59
|
-
insertSql
|
|
58
|
+
deleteSql(args) { return new Delete(Object.assign({driver: this}, args)).toSql() }
|
|
59
|
+
getType() { return "sqlite" }
|
|
60
|
+
insertSql(args) { return new Insert(Object.assign({driver: this}, args)).toSql() }
|
|
60
61
|
|
|
61
62
|
async getTableByName(tableName, args) {
|
|
62
63
|
const result = await this.query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${this.quote(tableName)} LIMIT 1`)
|
|
@@ -148,8 +149,8 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
148
149
|
return this._options
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
primaryKeyType
|
|
152
|
-
queryToSql
|
|
152
|
+
primaryKeyType() { return "integer" } // Because bigint on SQLite doesn't support auto increment
|
|
153
|
+
queryToSql(query) { return new QueryParser({query}).toSql() }
|
|
153
154
|
|
|
154
155
|
async registerVersion() {
|
|
155
156
|
if (this.versionMajor || this.versionMinor) {
|
|
@@ -167,7 +168,7 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
167
168
|
this.versionPatch = versionParts[2]
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
shouldSetAutoIncrementWhenPrimaryKey
|
|
171
|
+
shouldSetAutoIncrementWhenPrimaryKey() { return false }
|
|
171
172
|
|
|
172
173
|
escape(value) {
|
|
173
174
|
value = this._convertValue(value)
|
|
@@ -182,6 +183,26 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
182
183
|
return result
|
|
183
184
|
}
|
|
184
185
|
|
|
186
|
+
async query(sql) {
|
|
187
|
+
let tries = 0
|
|
188
|
+
|
|
189
|
+
while(tries < 5) {
|
|
190
|
+
tries++
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
return await this._queryActual(sql)
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (tries < 5 && error.message.includes("attempt to write a readonly database")) {
|
|
196
|
+
await wait(100)
|
|
197
|
+
this.logger.warn(`Retrying query because failed with: ${error.stack}`)
|
|
198
|
+
// Retry
|
|
199
|
+
} else {
|
|
200
|
+
throw error
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
185
206
|
quote(value) {
|
|
186
207
|
value = this._convertValue(value)
|
|
187
208
|
|
|
@@ -193,5 +214,5 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
193
214
|
return escapeString(value)
|
|
194
215
|
}
|
|
195
216
|
|
|
196
|
-
updateSql
|
|
217
|
+
updateSql({conditions, data, tableName}) { return new Update({conditions, data, driver: this, tableName}).toSql() }
|
|
197
218
|
}
|
|
@@ -56,9 +56,7 @@ export default class VelociousDatabaseDriversSqliteNative extends Base {
|
|
|
56
56
|
this.connection = undefined
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async
|
|
60
|
-
console.error("Native SQL: ", sql)
|
|
61
|
-
|
|
59
|
+
async _queryActual(sql) {
|
|
62
60
|
if (!this.connection) throw new Error("Not connected yet")
|
|
63
61
|
|
|
64
62
|
return await query(this.connection, sql)
|
package/src/logger.js
CHANGED
|
@@ -12,6 +12,12 @@ function consoleError(message) {
|
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function consoleWarn(message) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
process.stderr.write(`${message}\n`, "utf8", resolve)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
function functionOrMessages(messages) {
|
|
16
22
|
if (messages.length === 1 && typeof messages[0] == "function") {
|
|
17
23
|
messages = messages[0]()
|
|
@@ -75,6 +81,10 @@ class Logger {
|
|
|
75
81
|
async error(...messages) {
|
|
76
82
|
await consoleError(messagesToMessage(this._subject, ...functionOrMessages(messages)))
|
|
77
83
|
}
|
|
84
|
+
|
|
85
|
+
async warn(...messages) {
|
|
86
|
+
await consoleWarn(messagesToMessage(this._subject, ...functionOrMessages(messages)))
|
|
87
|
+
}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export {Logger}
|