npm oracle,NPM Oracle: Inserting BLOBs

I am trying to use the NPM oracle library and update some tables with BLOB values created from files on my computer. Oracle documentation says to use the createLob() function like the following in order to get a value the database will accept:

conn.createLob(oracledb.BLOB, function(err, templob) {

if (err) { . . . }

// ... else use templob

});

But I have no idea what "use templob" implies...

How do I get my data into these oracledb.BLOB objects?

EDIT: Example of update I am attempting:

const queryString = `UPDATE TABLENAME SET BLOB = :blob WHERE ID = 1234;`;

this.oracleConnection.execute(queryString,

{blob: await fs.readFileSync('/path/to/image.jpg')}

)

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

Based on your use case (small files and limited concurrency), I think the buffer APIs will be the best bet as they are very simple. From the doc:

Given the table:

CREATE TABLE mylobs (id NUMBER, c CLOB, b BLOB);

an INSERT example is:

var fs = require('fs');

var str = fs.readFileSync('example.txt', 'utf8');

. . .

conn.execute(

`INSERT INTO mylobs (id, myclobcol) VALUES (:idbv, :cbv)`,

{ idbv: 1,

cbv: str }, // type and direction are optional for IN binds

function(err, result) {

if (err)

console.error(err.message);

else

console.log('CLOB inserted from example.txt');

. . .

Also, in case you ever need it, I'm wrapping up a mini-series on this topic but it's framed more around web server uploads: https://jsao.io/2019/06/uploading-and-downloading-files-with-node-js-and-oracle-database/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值