This commit is contained in:
tdurieux
2021-03-16 11:23:16 +01:00
parent 141d016aae
commit a2d0f0b212
475 changed files with 23855 additions and 3869 deletions

39
utils/database.js Normal file
View File

@@ -0,0 +1,39 @@
const config = require("../config");
var MongoClient = require("mongodb").MongoClient;
const MONGO_URL = "mongodb://root:rootpassword@mongodb:27017/?authSource=admin";
let mongoClient = null;
let DB = null;
module.exports.get = (collection) => {
if (!collection) return DB;
return DB.collection(collection);
};
module.exports.connect = async () => {
mongoClient = await MongoClient.connect(
MONGO_URL,
{ useNewUrlParser: true, useUnifiedTopology: true }
);
DB = mongoClient.db("anonymous_github");
await DB.collection("anonymized_repositories").createIndex(
{ repoId: 1 },
{ unique: true, name: "repoId" }
);
await DB.collection("anonymized_repositories").createIndex(
{ fullName: 1 },
{ name: "fullName" }
);
await DB.collection("repositories").createIndex(
{ fullName: 1 },
{ unique: true, name: "fullName" }
);
await DB.collection("users").createIndex(
{ username: 1 },
{ unique: true, name: "username" }
);
return DB;
};
module.exports.close = async () => {
return await mongoClient.close();
};