How to pack correctly Tarantool iproto SQL bind custom type?

24 Views Asked by At

I am using Tarantool-driver it is npm package JavaScript connector to Tarantool

Every thing working just fine the problem with UUID, or custom type in SQL Bind parameter e.g.

function uuidPacker(uuidValue) {
  const uuidBytes = uuid.parse(uuidValue);

  // Create a Buffer with the extension type (MP_EXT) as 0xd8 and the extension type value (MP_UUID) as 0x02
  const extensionBuffer = Buffer.from([0xd8, 0x02]);

  // Combine the extension buffer with the UUID bytes
  const packedData = Buffer.concat([extensionBuffer, uuidBytes]);

 // Return the packed data as a Buffer
  return packedData;
}
     connection.sql(`SELECT "id","user_uuid" FROM "users_space" WHERE "user_uuid"=?`, [uuidPacker("6c7ba002-6beb-4bad-aca8-91609e26f2de")])

And I checked Tarantool-driver command.js could be problem function Commands.prototype.sql() but I don't know how to rebuild pack or custom

Commands.prototype.sql = function(query, bindParams = []){
_this = this;
return new Promise(function (resolve, reject) {
var reqId = _this._getRequestId();
var bufQuery = _this.msgpack.encode(query);
var bufParams = _this.msgpack.encode(bindParams);
var len = 12+bufQuery.length + bufParams.length;
var buffer = utils.createBuffer(len+5);

buffer[0] = 0xce;
buffer.writeUInt32BE(len, 1);
buffer[5] = 0x82;
buffer[6] = tarantoolConstants.KeysCode.code;
buffer[7] = tarantoolConstants.RequestCode.rqExecute;
buffer[8] = tarantoolConstants.KeysCode.sync;
buffer[9] = 0xce;
buffer.writeUInt32BE(reqId, 10);
buffer[14] = 0x82;
buffer.writeUInt8(tarantoolConstants.KeysCode.sql_text, 15);
bufQuery.copy(buffer, 16);
buffer[16+bufQuery.length] = tarantoolConstants.KeysCode.sql_bind;
bufParams.copy(buffer, 17+bufQuery.length);

_this.sendCommand([tarantoolConstants.RequestCode.rqExecute, reqId, {resolve: resolve, reject: reject}], buffer);
 });
};
0

There are 0 best solutions below