sqmicro-streams
Version:
SQ micro streams.
37 lines (28 loc) • 969 B
JavaScript
const { ConnectionStream } = require('../');
module.exports = class MySqlStream extends ConnectionStream {
async clean(keys) {
if (!keys || keys.size < 1) {
return;
}
let SQL = `DELETE * FROM my_table WHERE keys IN (${[...keys].join(',')})`;
return await this.connection.query(SQL);
}
async copy(rows) {
let SQL = `COPY my_table(key, value) FROM STDIN (DELIMITER '|')`;
return this.connection.copy(SQL, rows);
}
async mapEvent(ev) {
await this.clean(ev.refreshKeys);
await this.copy(ev.rows);
}
validateConnection(c) {
const errors = [];
if (typeof c.query !== 'function') {
errors.push('Connection instance should have query() method.');
}
if (typeof c.copy !== 'function') {
errors.push('Connection instance should have copy() method');
}
return errors;
}
};