Skip to content

Commit 56a9668

Browse files
committed
Update code
1 parent 06bfa7c commit 56a9668

File tree

8 files changed

+104
-973
lines changed

8 files changed

+104
-973
lines changed

express-app/db-adapters/demo-surveys.js

-636
This file was deleted.

express-app/db-adapters/in-memory.js

-121
This file was deleted.

express-app/db-adapters/mongo.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22
const { MongoClient, ObjectId } = require('mongodb');
3-
const NoSQLCRUDAdapter = require("./nosql-crud-adapter");
3+
const NoSqlCrudAdapter = require("./nosql-crud-adapter");
44
const SurveyStorage = require("./survey-storage");
55

66
const readFileSync = filename => fs.readFileSync(filename).toString("utf8");
@@ -16,16 +16,15 @@ const dbConfig = {
1616
};
1717

1818
const url = `mongodb://${dbConfig.user}:${dbConfig.password}@${dbConfig.host}:${dbConfig.port}/`;
19-
// console.log(url);
2019
const client = new MongoClient(url);
2120

22-
function MongoStorage(session) {
23-
function dbConnectFunction(dbCallback) {
21+
function MongoStorage() {
22+
function dbConnectFunction (dbCallback) {
2423
client.connect()
2524
.then(() => {
2625
const db = client.db(dbConfig.database);
27-
dbCallback(db, function() {
28-
if(!!process.env.DATABASE_LOG) {
26+
dbCallback(db, () => {
27+
if (!!process.env.DATABASE_LOG) {
2928
console.log(arguments[0]);
3029
console.log(arguments[1]);
3130
}
@@ -36,7 +35,7 @@ function MongoStorage(session) {
3635
console.error(JSON.stringify(arguments));
3736
});
3837
}
39-
const dbQueryAdapter = new NoSQLCRUDAdapter(dbConnectFunction, () => new ObjectId().toString());
38+
const dbQueryAdapter = new NoSqlCrudAdapter(dbConnectFunction, () => new ObjectId().toString());
4039
return new SurveyStorage(dbQueryAdapter);
4140
}
4241

express-app/db-adapters/nosql-crud-adapter.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function NoSQLCRUDAdapter(dbConnectFunction, getId) {
2-
function getObjects(collectionName, filter, callback) {
1+
function NoSqlCrudAdapter (dbConnectFunction, getId) {
2+
function getObjects (collectionName, filter, callback) {
33
filter = filter || [];
44
let query = {};
55
filter.forEach(fi => query[fi.name] = fi.value);
@@ -16,7 +16,7 @@ function NoSQLCRUDAdapter(dbConnectFunction, getId) {
1616
);
1717
}
1818

19-
function deleteObject(collectionName, idValue, callback) {
19+
function deleteObject (collectionName, idValue, callback) {
2020
dbConnectFunction((db, finalizeCallback) => {
2121
db.collection(collectionName).deleteMany({ id: idValue })
2222
.then((results) => {
@@ -30,7 +30,7 @@ function NoSQLCRUDAdapter(dbConnectFunction, getId) {
3030
);
3131
}
3232

33-
function createObject(collectionName, object, callback) {
33+
function createObject (collectionName, object, callback) {
3434
object.id = object.id || getId();
3535
dbConnectFunction((db, finalizeCallback) => {
3636
db.collection(collectionName).insertOne(object)
@@ -45,7 +45,7 @@ function NoSQLCRUDAdapter(dbConnectFunction, getId) {
4545
);
4646
}
4747

48-
function updateObject(collectionName, object, callback) {
48+
function updateObject (collectionName, object, callback) {
4949
dbConnectFunction((db, finalizeCallback) => {
5050
db.collection(collectionName).updateOne({ id: object.id }, { $set: object })
5151
.then((results) => {
@@ -67,4 +67,4 @@ function NoSQLCRUDAdapter(dbConnectFunction, getId) {
6767
}
6868
}
6969

70-
module.exports = NoSQLCRUDAdapter;
70+
module.exports = NoSqlCrudAdapter;

express-app/db-adapters/postgres.js

-32
This file was deleted.

express-app/db-adapters/sql-crud-adapter.js

-75
This file was deleted.

0 commit comments

Comments
 (0)