velocious 1.0.73 → 1.0.75

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.73",
6
+ "version": "1.0.75",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
@@ -106,6 +106,13 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
106
106
  return false
107
107
  }
108
108
 
109
+ supportsInsertIntoReturning() {
110
+ if (this.versionMajor >= 4) return true
111
+ if (this.versionMajor == 3 && this.versionMinor >= 35) return true
112
+
113
+ return false
114
+ }
115
+
109
116
  async insertMultipleWithSingleInsert(tableName, columns, rows) {
110
117
  const sql = new Insert({columns, driver: this, rows, tableName}).toSql()
111
118
 
@@ -49,7 +49,7 @@ export default class VelociousDatabaseQuery {
49
49
 
50
50
  async count() {
51
51
  // Generate count SQL
52
- let sql = "COUNT(id)"
52
+ let sql = `COUNT(${this.driver.quoteTable(this.modelClass.tableName())}.${this.driver.quoteColumn(this.modelClass.primaryKey())})`
53
53
 
54
54
  if (this.driver.getType() == "pgsql") sql += "::int"
55
55
 
@@ -151,8 +151,8 @@ export default class VelociousDatabaseQuery {
151
151
  }
152
152
 
153
153
  async first() {
154
- const newQuery = this.clone()
155
- const results = await newQuery.limit(1).reorder(this.modelClass.orderableColumn()).toArray()
154
+ const newQuery = this.clone().limit(1).reorder(this.modelClass.orderableColumn())
155
+ const results = await newQuery.toArray()
156
156
 
157
157
  return results[0]
158
158
  }
@@ -34,7 +34,7 @@ export default class VelociousDatabaseQueryInsertBase {
34
34
  if (Object.keys(this.data).length <= 0) {
35
35
  sql += lastInsertedSQL
36
36
  }
37
- } else if (driver.getType() == "mysql" || driver.getType() == "pgsql") {
37
+ } else if (driver.getType() == "mysql" || driver.getType() == "pgsql" || (driver.getType() == "sqlite" && driver.supportsInsertIntoReturning())) {
38
38
  lastInsertedSQL = ` RETURNING ${driver.quoteColumn(this.returnLastInsertedColumnName)} AS lastInsertID`
39
39
  }
40
40
  }
@@ -89,7 +89,7 @@ export default class VelociousDatabaseQueryInsertBase {
89
89
  }
90
90
 
91
91
  if (this.returnLastInsertedColumnName) {
92
- if (driver.getType() == "mysql") {
92
+ if (driver.getType() == "mysql" || (driver.getType() == "sqlite" && driver.supportsInsertIntoReturning())) {
93
93
  sql += lastInsertedSQL
94
94
  }
95
95
  }
@@ -225,6 +225,9 @@ class Expect {
225
225
 
226
226
  for (const key in result) {
227
227
  const value = result[key]
228
+
229
+ if (!(key in this._object)) throw new Error(`${this._object.constructor.name} doesn't respond to ${key}`)
230
+
228
231
  const objectValue = this._object[key]()
229
232
 
230
233
  if (value != objectValue) {