ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

New Feature/Enhancement Request: Stream data into a blob instead of having entire buffer in memory #962

Open trsvax opened 8 months ago

trsvax commented 8 months ago

Is your feature request related to a problem? Please describe. There are times when it would be nice to stream data into a blob and not have the entire buffer in memory

Describe the solution you'd like While looking for solutions Github co pilot generated this

const file = fs.createReadStream(path/to/${sid.trim()}_flash_notice.pdf); const conn = ibmdb.openSync(‘DATABASE=;HOSTNAME=;UID=;PWD=;PORT=’); const stmt = conn.prepareSync(‘INSERT INTO foo (id, pdf) VALUES (?, ?)’); const lob = conn.createLob(ibmdb.SQL_BLOB); stmt.execute([sid.trim(), lob], (err) => { if (err) { console.error(err); return; } file.on(‘data’, (chunk) => { lob.write(chunk); }); file.on(‘end’, () => { lob.closeSync(); }); archive.append(lob, { name: ${sid.trim()}_flash_notice.pdf }); }); });

Describe alternatives you've considered It's currently possible to write a file then insert that. Not sure if that just reads the file into memory and inserts it.

Additional context I'm not an ODBC expert but the above seems possible via the C interface. It's interesting that co pilot suggested it.

bimalkjha commented 7 months ago

Internal: Opened Epic https://jira.rocketsoftware.com/browse/DBC-14896 in Jira for this enhancement request. Currently planned for 1H2024. Thanks.