-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 952 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require("dotenv").config();
const fs = require("fs");
const { get, convertToPostgres } = require("./src/services/sqlite.service");
const { insert } = require("./src/services/postgres.service");
const config = require("./src/config/config");
const postModel = require("./database/Models/Posts");
/**
* Function that start all convertion
*
* @param {String} table - Table name in Sqlite database
* @param {Object} model - Model object with table typs (check docs)
*/
async function main(table, model) {
if (!table) {
throw new Error("Table not found");
}
let sql = "";
const data = await get(table);
data.forEach((post) => {
const returnSql = convertToPostgres(post, model, table);
sql = `${sql} ${returnSql}`;
});
if (config.sql_to_file) {
fs.writeFileSync(`${table}.sql`, sql);
}
if (!config.dont_insert) {
await insert(sql);
}
console.info(`Table ${table} done.`);
}
main("posts", postModel);