MCPcopy Create free account
hub / github.com/electric-sql/pglite / writeValues

Function writeValues

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

Source from the content-addressed store, hash-verified

128}
129
130const writeValues = (values: LegalValue[], valueMapper?: ValueMapper): void => {
131 for (let i = 0; i < values.length; i++) {
132 const mappedVal = valueMapper ? valueMapper(values[i], i) : values[i]
133 if (mappedVal === null) {
134 // add the param type (string) to the writer
135 writer.addInt16(ParamType.STRING)
136 // write -1 to the param writer to indicate null
137 paramWriter.addInt32(-1)
138 } else if (
139 mappedVal instanceof ArrayBuffer ||
140 ArrayBuffer.isView(mappedVal)
141 ) {
142 const buffer = ArrayBuffer.isView(mappedVal)
143 ? mappedVal.buffer.slice(
144 mappedVal.byteOffset,
145 mappedVal.byteOffset + mappedVal.byteLength,
146 )
147 : mappedVal
148 // add the param type (binary) to the writer
149 writer.addInt16(ParamType.BINARY)
150 // add the buffer to the param writer
151 paramWriter.addInt32(buffer.byteLength)
152 paramWriter.add(buffer)
153 } else {
154 // add the param type (string) to the writer
155 writer.addInt16(ParamType.STRING)
156 paramWriter.addInt32(byteLengthUtf8(mappedVal))
157 paramWriter.addString(mappedVal)
158 }
159 }
160}
161
162const bind = (config: BindOpts = {}): Uint8Array => {
163 // normalize config

Callers 1

bindFunction · 0.85

Calls 5

byteLengthUtf8Function · 0.90
addInt16Method · 0.45
addInt32Method · 0.45
addMethod · 0.45
addStringMethod · 0.45

Tested by

no test coverage detected