dbgate/test/importTable.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

const dbgateApi = require('dbgate-api');
2020-06-10 19:35:25 +00:00
async function run() {
const csvReader = await dbgateApi.csvReader({
fileName: 'test.csv',
2020-06-11 08:19:38 +00:00
// header: false,
2020-06-10 19:35:25 +00:00
});
2020-06-11 13:58:19 +00:00
const excelReader = await dbgateApi.excelSheetReader({
fileName: '/home/jena/Downloads/events-Jan_Prochazka.xlsx',
sheetName: 'Events',
});
2020-06-11 18:52:57 +00:00
const jsonReader = await dbgateApi.jsonLinesReader({
fileName: 'test.jsonl',
header: false,
});
2020-06-11 11:58:34 +00:00
const tableWriter = await dbgateApi.tableWriter({
connection: {
server: 'localhost',
engine: 'mssql',
user: 'sa',
password: 'Pwd2020Db',
database: 'Chinook',
},
schemaName: 'dbo',
2020-06-11 18:52:57 +00:00
pureName: 'Genre3',
2020-06-11 11:58:34 +00:00
createIfNotExists: true,
truncate: true,
});
2020-06-10 19:35:25 +00:00
2020-06-11 08:19:38 +00:00
// const tableWriter = await dbgateApi.tableWriter({
// connection: {
// server: 'localhost',
// engine: 'mysql',
// user: 'root',
// password: 'test',
// port: '3307',
// database: 'Chinook',
// },
// pureName: 'importedTable'
// });
2020-06-10 19:35:25 +00:00
const consoleWriter = await dbgateApi.consoleObjectWriter();
2020-06-11 13:58:19 +00:00
// await dbgateApi.copyStream(excelReader, consoleWriter);
2020-06-11 18:52:57 +00:00
await dbgateApi.copyStream(jsonReader, tableWriter);
2020-06-11 11:58:34 +00:00
// await dbgateApi.copyStream(csvReader, consoleWriter);
2020-06-11 13:58:19 +00:00
// await dbgateApi.copyStream(csvReader, tableWriter);
2020-06-10 19:35:25 +00:00
}
dbgateApi.runScript(run);