Skip to content

Commit

Permalink
Add support for creating the gxitproxy table in PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
kysrpex committed Jul 4, 2024
1 parent dc042e6 commit b2bf83c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 30 additions & 4 deletions lib/createdb.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node
const args = require("commander");
const packageInfo = require("../package");
const { startsWith } = require("./mapper");
var postgresClient = require("pg-native");
var sqlite3 = require("sqlite3");

args
.version(packageInfo.version)
.option("--sessions <file>", "Routes file to monitor")
.option("--verbose");

const main = function (argv_) {
const argv = argv_ || process.argv;
args.parse(argv);
let db = new sqlite3.Database(args.sessions, (err) => {
const createDbSqlite = function (sessions) {
let db = new sqlite3.Database(sessions, (err) => {
if (err) {
return console.error(err.message);
}
Expand All @@ -36,6 +36,32 @@ CREATE TABLE gxitproxy
db.close();
};

const createDbPostgres = function (sessions) {
const db = postgresClient();
db.connectSync(sessions);
db.querySync(`
CREATE TABLE IF NOT EXISTS gxitproxy (
key text,
key_type text,
token text,
host text,
port integer,
info text,
PRIMARY KEY (key, key_type)
);`
)
};

const main = function (argv_) {
const argv = argv_ || process.argv;
args.parse(argv);
if (startsWith(args.sessions, "postgresql://")) {
createDbPostgres(args.sessions);
} else {
createDbSqlite(args.sessions);
}
}

exports.main = main;

if (require.main === module) {
Expand Down
2 changes: 2 additions & 0 deletions lib/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ var mapFor = function (path, pollingInterval) {
return map;
};

exports.endsWith = endsWith;
exports.mapFor = mapFor;
exports.startsWith = startsWith;

0 comments on commit b2bf83c

Please sign in to comment.