feat: libsql basic support

This commit is contained in:
Nybkox
2025-03-11 15:11:35 +01:00
parent ba9e124527
commit 75b2debf0a
14 changed files with 368 additions and 51 deletions

View File

@@ -0,0 +1,49 @@
// @ts-check
function runStreamItem(dbhan, sql, options, rowCounter) {
const stmt = dbhan.client.prepare(sql);
console.log(stmt);
console.log(stmt.reader);
if (stmt.reader) {
const columns = stmt.columns();
// const rows = stmt.all();
options.recordset(
columns.map((col) => ({
columnName: col.name,
dataType: col.type,
}))
);
for (const row of stmt.iterate()) {
options.row(row);
}
} else {
const info = stmt.run();
rowCounter.count += info.changes;
if (!rowCounter.date) rowCounter.date = new Date().getTime();
if (new Date().getTime() - rowCounter.date > 1000) {
options.info({
message: `${rowCounter.count} rows affected`,
time: new Date(),
severity: 'info',
});
rowCounter.count = 0;
rowCounter.date = null;
}
}
}
async function waitForDrain(stream) {
return new Promise((resolve) => {
stream.once('drain', () => {
// console.log('CONTINUE DRAIN');
resolve();
});
});
}
module.exports = {
runStreamItem,
waitForDrain,
};