| 24 | } |
| 25 | |
| 26 | getSQLTypeFromJsType(value, TYPES) { |
| 27 | const paramType = { type: TYPES.NVarChar, typeOptions: {}, value }; |
| 28 | if (typeof value === 'number') { |
| 29 | if (Number.isInteger(value)) { |
| 30 | if (value >= -2147483648 && value <= 2147483647) { |
| 31 | paramType.type = TYPES.Int; |
| 32 | } else { |
| 33 | paramType.type = TYPES.BigInt; |
| 34 | } |
| 35 | } else { |
| 36 | paramType.type = TYPES.Numeric; |
| 37 | //Default to a reasonable numeric precision/scale pending more sophisticated logic |
| 38 | paramType.typeOptions = { precision: 30, scale: getScale(value) }; |
| 39 | } |
| 40 | } else if (typeof value === 'bigint') { |
| 41 | if (value < minSafeIntegerAsBigInt || value > maxSafeIntegerAsBigInt) { |
| 42 | paramType.type = TYPES.VarChar; |
| 43 | paramType.value = value.toString(); |
| 44 | } else { |
| 45 | return this.getSQLTypeFromJsType(Number(value), TYPES); |
| 46 | } |
| 47 | } else if (typeof value === 'boolean') { |
| 48 | paramType.type = TYPES.Bit; |
| 49 | } |
| 50 | if (Buffer.isBuffer(value)) { |
| 51 | paramType.type = TYPES.VarBinary; |
| 52 | } |
| 53 | return paramType; |
| 54 | } |
| 55 | |
| 56 | async _run(connection, sql, parameters, errStack) { |
| 57 | this.sql = sql; |