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