dbgate/test/importTable.js

42 lines
967 B
JavaScript
Raw Normal View History

2020-06-10 19:35:25 +00:00
const dbgateApi = require('@dbgate/api');
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 11:58:34 +00:00
const tableWriter = await dbgateApi.tableWriter({
connection: {
server: 'localhost',
engine: 'mssql',
user: 'sa',
password: 'Pwd2020Db',
database: 'Chinook',
},
schemaName: 'dbo',
pureName: 'Genre2',
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 11:58:34 +00:00
// await dbgateApi.copyStream(csvReader, consoleWriter);
await dbgateApi.copyStream(csvReader, tableWriter);
2020-06-10 19:35:25 +00:00
}
dbgateApi.runScript(run);