Skip to content

Commit 9ec5077

Browse files
committed
Support varchar
1 parent db8469b commit 9ec5077

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ For all supported types, their corresponding array version is also supported.
285285
- int2, int4
286286
- float4, float8
287287
- text
288+
- varchar
288289
- json
289290
- jsonb
290291
- timestamptz

lib/pg_types.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const textrecv = function (buf) {
4242
return buf.toString('utf-8')
4343
}
4444

45+
// varchar
46+
const varcharsend = textsend
47+
const varcharrecv = textrecv
48+
4549
// json
4650
const json_send = function (buf, value) {
4751
const jbuf = Buffer.from(JSON.stringify(value), 'utf-8')
@@ -193,6 +197,7 @@ const types = {
193197
int2: { oid: 21, send: int2send, recv: int2recv },
194198
int4: { oid: 23, send: int4send, recv: int4recv },
195199
text: { oid: 25, send: textsend, recv: textrecv },
200+
varchar: { oid: 1043, send: varcharsend, recv: varcharrecv },
196201
json: { oid: 114, send: json_send, recv: json_recv },
197202
jsonb: { oid: 3802, send: jsonb_send, recv: jsonb_recv },
198203
float4: { oid: 700, send: float4send, recv: float4recv },
@@ -203,6 +208,7 @@ const types = {
203208
_int2: { oid: 1005, send: array_send.bind(null, 'int2'), recv: array_recv },
204209
_int4: { oid: 1007, send: array_send.bind(null, 'int4'), recv: array_recv },
205210
_text: { oid: 1009, send: array_send.bind(null, 'text'), recv: array_recv },
211+
_varchar: { oid: 1015, send: array_send.bind(null, 'varchar'), recv: array_recv },
206212
_json: { oid: 199, send: array_send.bind(null, 'json'), recv: array_recv },
207213
_jsonb: { oid: 3807, send: array_send.bind(null, 'jsonb'), recv: array_recv },
208214
_float4: { oid: 1021, send: array_send.bind(null, 'float4'), recv: array_recv },

test/samples.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module.exports = [
2828
{ t: 'text', v: null, r: new BP().word32be(-1).buffer() },
2929
{ t: 'text', v: 'hello', r: new BP().word32be(5).put(Buffer.from('hello')).buffer() },
3030
{ t: 'text', v: 'utf8 éà', r: new BP().word32be(9).put(Buffer.from('utf8 éà', 'utf-8')).buffer() },
31+
{ t: 'varchar', v: null, r: new BP().word32be(-1).buffer() },
32+
{ t: 'varchar', v: 'hello', r: new BP().word32be(5).put(Buffer.from('hello')).buffer() },
33+
{ t: 'varchar', v: 'utf8 éà', r: new BP().word32be(9).put(Buffer.from('utf8 éà', 'utf-8')).buffer() },
3134
{ t: 'json', v: null, r: new BP().word32be(-1).buffer() },
3235
{ t: 'json', v: { a: true, b: [1, 7] }, r: new BP().word32be(20).string('{"a":true,"b":[1,7]}', 'utf-8').buffer() },
3336
{ t: 'jsonb', v: null, r: new BP().word32be(-1).buffer() },
@@ -184,6 +187,25 @@ module.exports = [
184187
.word8(100)
185188
.buffer(),
186189
},
190+
{ t: '_varchar', v: null, r: new BP().word32be(-1).buffer() },
191+
{
192+
t: '_varchar',
193+
v: ['ab', 'cd'],
194+
r: new BP()
195+
.word32be(32)
196+
.word32be(1)
197+
.word32be(0)
198+
.word32be(types['varchar'].oid)
199+
.word32be(2)
200+
.word32be(1)
201+
.word32be(2)
202+
.word8(97)
203+
.word8(98)
204+
.word32be(2)
205+
.word8(99)
206+
.word8(100)
207+
.buffer(),
208+
},
187209
{ t: '_json', v: null, r: new BP().word32be(-1).buffer() },
188210
{
189211
t: '_json',

0 commit comments

Comments
 (0)