Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

bytea support, not 1 : 1 in javascript/native #184

Closed
ghost opened this Issue · 3 comments

2 participants

@ghost

In native, it kind of works how you would've figure it should work...
It wants a byte array or else your data will get clipped. It'll give you back a Buffer of the literal string byte array you gave it. So you need to convert this back.

In javascript, it'll take anything, it'll treat it as string, that means it'll complain about non escaped text. It'll give you back a string. You'd have to escape this or encode it as hex or base64. Then decode it later when you retrieve it.

@mamayoleksandr

exactly same issue here. So how to properly save bytea data? In statement with parameters provided data is cut in native mode.

@mamayoleksandr

In both modes (js and native) works following solution:
fs.readFile(self.c.req.files.attachment.path,'hex', function(err, data){
if (err) {
clbSer(err);
} else {

params.attachment_data = '\x' + data;

params.attachment_name = self.c.req.files.attachment.name;
//attachment_data can be inserted as conn.query('insert into table (byteaColumn) VALUES ($1)', [params.attachment_data]);
clbSer(null, params);
}
});

conn.query('select byteaResult ...', function(err, res){
fs.writeFile(res.rows[0].byteaResult, function(err, res){});
});

@polastre polastre referenced this issue in balderdashy/sails-postgresql
Merged

Add binary datatype support for Postgres BYTEA #11

@polastre polastre referenced this issue from a commit in Innovation-Toolkit/sails-postgresql
@polastre polastre Add binary datatype support for Postgres BYTEA
Waterline supports binary datatypes, so map them to BYTEA column
types in Postgres.  Convert buffers to hex strings (as per the
tradition in node-postgres) starting with \x, which will automatically
be converted back into Buffer objects when read from Postgres by
node-postgres.

See
brianc/node-postgres#184
and
parseByteA of https://github.com/brianc/node-postgres/blob/master/lib/types/textParsers.js
2a0f248
@brianc
Owner

I think this is fixed, right? node-pg-types has had a byte array parser for quite a while.

@brianc brianc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.