Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c904310

Browse files
committedNov 18, 2021
Add database connection and commands
1 parent be7dfe7 commit c904310

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
 

‎pg-driver.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const Promise = require('bluebird')
2+
3+
const pg = require('pg-promise')({
4+
promiseLib: Promise,
5+
})
6+
7+
const client = pg({
8+
host: "127.0.0.1",
9+
port: 5432,
10+
database: "postgres",
11+
});
12+
13+
const insertNpmDownloadData = (packageName, count) =>
14+
{
15+
var query = pg.as.format(
16+
"INSERT INTO npm_downloads_count VALUES ($1, $2);",
17+
[packageName, count]
18+
);
19+
return client.oneOrNone(query);
20+
};
21+
22+
const getNpmDownloadData = (packageName) =>
23+
{
24+
var query = pg.as.format(
25+
"SELECT * FROM npm_downloads_count WHERE name = $1 LIMIT 1;",
26+
[packageName]
27+
);
28+
29+
return client.any(query);
30+
};
31+
32+
const insertNpmInstallScriptsCheckRecord = (checkId, packageName, version, preinstall, install, postinstall, prepublish, preprepare, prepare, postprepare, gyp, state) =>
33+
{
34+
var query = pg.as.format("INSERT INTO npm_install_scripts_checker VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) ON CONFLICT DO NOTHING;", [
35+
checkId, packageName, version, preinstall, install, postinstall, prepublish, preprepare, prepare, postprepare, gyp, state
36+
]);
37+
38+
return client.oneOrNone(query);
39+
};
40+
41+
const getNpmInstallScriptsCheckRecord = (checkId, packageName) =>
42+
{
43+
var query = pg.as.format(
44+
"SELECT * FROM npm_install_scripts_checker WHERE check_id = $1 AND name = $2 LIMIT 1;",
45+
[checkId, packageName]
46+
);
47+
return client.oneOrNone(query);
48+
};
49+
50+
module.exports = {
51+
insertNpmDownloadData: insertNpmDownloadData,
52+
getNpmDownloadData: getNpmDownloadData,
53+
insertNpmInstallScriptsCheckRecord: insertNpmInstallScriptsCheckRecord,
54+
getNpmInstallScriptsCheckRecord: getNpmInstallScriptsCheckRecord,
55+
pg: pg,
56+
client: client,
57+
};

0 commit comments

Comments
 (0)
Please sign in to comment.