MCPcopy
hub / github.com/brianc/node-postgres / writeValues

Function writeValues

packages/pg-protocol/src/serializer.ts:121–142  ·  view source on GitHub ↗
(values: any[], valueMapper?: ValueMapper)

Source from the content-addressed store, hash-verified

119}
120
121const 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
144const bind = (config: BindOpts = {}): Buffer => {
145 // normalize config

Callers 1

bindFunction · 0.85

Calls 4

addInt16Method · 0.45
addInt32Method · 0.45
addMethod · 0.45

Tested by

no test coverage detected