(values: any[], valueMapper?: ValueMapper)
| 119 | } |
| 120 | |
| 121 | const writeValues = function (values: any[], valueMapper?: ValueMapper): void { |
| 122 | for (let i = 0; i < values.length; i++) { |
| 123 | const mappedVal = valueMapper ? valueMapper(values[i], i) : values[i] |
| 124 | if (mappedVal == null) { |
| 125 | // add the param type (string) to the writer |
| 126 | writer.addInt16(ParamType.STRING) |
| 127 | // write -1 to the param writer to indicate null |
| 128 | paramWriter.addInt32(-1) |
| 129 | } else if (mappedVal instanceof Buffer) { |
| 130 | // add the param type (binary) to the writer |
| 131 | writer.addInt16(ParamType.BINARY) |
| 132 | // add the buffer to the param writer |
| 133 | paramWriter.addInt32(mappedVal.length) |
| 134 | paramWriter.add(mappedVal) |
| 135 | } else { |
| 136 | // add the param type (string) to the writer |
| 137 | writer.addInt16(ParamType.STRING) |
| 138 | // length prefix + UTF-8 bytes in one pass (Buffer.byteLength computed once) |
| 139 | paramWriter.addInt32PrefixedString(mappedVal) |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | const bind = (config: BindOpts = {}): Buffer => { |
| 145 | // normalize config |
no test coverage detected