2020-06-04 09:18:46 +00:00
|
|
|
const dbgateApi = require('@dbgate/api');
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
const queryReader = await dbgateApi.queryReader({
|
|
|
|
connection: {
|
|
|
|
server: 'localhost',
|
|
|
|
engine: 'mysql',
|
|
|
|
user: 'root',
|
|
|
|
password: 'test',
|
|
|
|
port: '3307',
|
|
|
|
database: 'Chinook',
|
|
|
|
},
|
|
|
|
sql: 'SELECT * FROM Genre',
|
|
|
|
});
|
|
|
|
|
|
|
|
// const queryReader = await dbgateApi.fakeObjectReader({ delay: 1000 });
|
|
|
|
|
|
|
|
const csvWriter = await dbgateApi.csvWriter({
|
|
|
|
fileName: 'test.csv',
|
2020-06-10 19:35:25 +00:00
|
|
|
header: true,
|
2020-06-04 09:18:46 +00:00
|
|
|
});
|
|
|
|
|
2020-06-10 19:35:25 +00:00
|
|
|
const consoleWriter = await dbgateApi.consoleObjectWriter();
|
|
|
|
|
2020-06-04 09:18:46 +00:00
|
|
|
await dbgateApi.copyStream(queryReader, csvWriter);
|
2020-06-10 19:35:25 +00:00
|
|
|
// await dbgateApi.copyStream(queryReader, consoleWriter);
|
2020-06-04 09:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dbgateApi.runScript(run);
|
2020-06-06 19:48:29 +00:00
|
|
|
|
|
|
|
// dbgateApi.runBatch([
|
|
|
|
// {
|
|
|
|
// type: 'copyStream',
|
|
|
|
// source: {
|
|
|
|
// type: 'queryReader',
|
|
|
|
// connection: {
|
|
|
|
// server: 'localhost',
|
|
|
|
// engine: 'mysql',
|
|
|
|
// user: 'root',
|
|
|
|
// password: 'test',
|
|
|
|
// port: '3307',
|
|
|
|
// database: 'Chinook',
|
|
|
|
// },
|
|
|
|
// sql: 'SELECT * FROM Genre',
|
|
|
|
// },
|
|
|
|
// target: {
|
|
|
|
// type: 'csvWriter',
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// ]);
|