velocious 1.0.651 → 1.0.653

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.
@@ -3,6 +3,7 @@
3
3
  import * as inflection from "inflection"
4
4
  import {isPlainObject} from "is-plain-object"
5
5
  import WhereBase from "./where-base.js"
6
+ import WhereIn from "./where-in.js"
6
7
 
7
8
  /**
8
9
  * No match.
@@ -378,6 +379,34 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
378
379
  return normalized
379
380
  }
380
381
 
382
+ /**
383
+ * Normalizes explicit membership through the model's column metadata.
384
+ * @param {{modelClass: typeof import("../record/index.js").default, columnName: string, tableName?: string, condition: unknown}} args - Resolved column and untrusted membership descriptor.
385
+ * @returns {string} - Complete column membership predicate.
386
+ */
387
+ _whereSQLFromInCondition({modelClass, columnName, tableName, condition}) {
388
+ const options = this.getOptions()
389
+ const values = WhereIn.values(condition)
390
+ const normalizedValues = this._normalizeSqliteBooleanValue({columnName, modelClass, value: values})
391
+ /** @type {import("./where-in.js").InValue[] | typeof NO_MATCH} */
392
+ const typedValues = this._normalizeValueForColumnType({columnName, modelClass, value: normalizedValues})
393
+
394
+ if (typedValues === NO_MATCH) return "1=0"
395
+
396
+ const columnSql = tableName
397
+ ? `${options.quoteTableName(tableName)}.${options.quoteColumnName(columnName)}`
398
+ : options.quoteColumnName(columnName)
399
+ const columnType = modelClass.getColumnTypeByName(columnName)
400
+ const castText = this.getQuery().driver.getType() === "mssql" && columnType?.toLowerCase() === "text"
401
+
402
+ return WhereIn.toSql({
403
+ columnSql,
404
+ inColumnSql: castText ? `CAST(${columnSql} AS NVARCHAR(MAX))` : columnSql,
405
+ options,
406
+ values: typedValues
407
+ })
408
+ }
409
+
381
410
  /**
382
411
  * Runs where sqlfrom hash.
383
412
  * @param {WhereHash} hash - Hash.
@@ -400,7 +429,11 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
400
429
  : null
401
430
  const resolvedColumnName = this._resolveColumnName(modelClass, whereKey)
402
431
 
403
- if (relationship && tuples) {
432
+ if (resolvedColumnName && !relationship && isPlainObject(whereValue)) {
433
+ if (index > 0) sql += " AND "
434
+
435
+ sql += this._whereSQLFromInCondition({columnName: resolvedColumnName, condition: whereValue, modelClass, tableName})
436
+ } else if (relationship && tuples) {
404
437
  if (index > 0) sql += " AND "
405
438
 
406
439
  const rawTargetModelClass = relationship.getTargetModelClass()
@@ -180,12 +180,12 @@ export default class VelociousWebsocketClient extends SnapReqWebSocketClient {
180
180
  this.reconnectGeneration += 1
181
181
  await super.disconnectAndStopReconnect()
182
182
 
183
- if (this.runningReconnectTasks.size === 0) return
184
-
185
183
  while (this.runningReconnectTasks.size > 0) {
186
184
  await Promise.all(this.runningReconnectTasks)
187
185
  }
188
186
 
187
+ // A stale attempt may have finished during the first close after changing
188
+ // stopped state, even when the task set is already empty here.
189
189
  await super.disconnectAndStopReconnect()
190
190
  }
191
191
  }