-
Notifications
You must be signed in to change notification settings - Fork 4
/
runsql.js
46 lines (40 loc) · 931 Bytes
/
runsql.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
42
43
44
45
46
const pgp = require("pg-promise")();
const Config = require("good-config");
const path = require("path");
const config = new Config({
path: "./config",
format: "yml",
provider: "FileSystem"
});
function sql(file) {
const fullPath = path.join(__dirname, file);
return new pgp.QueryFile(fullPath, { debug: true });
}
async function seedMe(conf) {
const db = pgp({
user: conf.user,
host: conf.host,
password: conf.password,
database: conf.database,
port: conf.port
});
try {
const sqlFindUser = sql("./db.sql");
await db.any(sqlFindUser);
console.log("All done! gg ez!");
} catch (err) {
console.error("An error occurred:", err);
process.exitCode = 1;
} finally {
pgp.end();
}
}
async function main() {
await config.load();
const configData = config.getAll();
await seedMe(configData.db);
}
main().catch(err => {
console.log(err);
process.exit(1);
});