mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 16:13:58 +00:00
feat: libsql basic support
This commit is contained in:
49
plugins/dbgate-plugin-sqlite/src/backend/helpers.js
Normal file
49
plugins/dbgate-plugin-sqlite/src/backend/helpers.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user