Skip to content

Commit

Permalink
* [Fix] Fixing and Maintaining the database structure and exposed api…
Browse files Browse the repository at this point in the history
…s through the code base

+ [Add] Adding the Repository pattern into the code for switching the databases and better data access flow controls
  • Loading branch information
mohammadhb committed Apr 25, 2021
1 parent 5f4d586 commit d7411c2
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 341 deletions.
17 changes: 0 additions & 17 deletions database/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions database/mongodb/config.js

This file was deleted.

21 changes: 0 additions & 21 deletions database/mongodb/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions database/postgresql/config.js

This file was deleted.

34 changes: 0 additions & 34 deletions database/postgresql/index.js

This file was deleted.

87 changes: 0 additions & 87 deletions database/redis/index.js

This file was deleted.

114 changes: 0 additions & 114 deletions database/redis/models/user.model.js

This file was deleted.

46 changes: 46 additions & 0 deletions databases/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const redis = require("./redis/index.js");
const mongodb = require("./mongodb/index.js");
const postgresql = require("./postgresql/index.js");
const { database:{config,database} } = require("../config");

// Redis Connection Helpers
const startRedis = ()=>{
redis.connectDatabase(config, console.error.bind(console, "connection error:"), () => {});
};
const stopRedis = ()=>{
redis.disconnectDatabase();
};

// Mongo DB Connection Helpers
const startMongoDB = ()=>{
mongodb.connectDatabase(config, console.error.bind(console, "connection error:"), () => {
console.log("MongoDB is Connected.");
});
};
const stopMongoDB = ()=>{
mongodb.getConnection().close();
};

// Redis Connection Helpers
const startPostgresql = ()=>{
postgresql.connectDatabase(config, console.error.bind(console, "connection error:"), () => {});
postgresql.connectModels(postgresql.getClient());
};
const stopPostgresql = ()=>{
postgresql.getClient().close();
};

module.exports = {
database,
temporary:{
start:startRedis,
stop:stopRedis,
manager:redis,
},
persistant:{
start:database==="POSTGRESQL"?startPostgresql:startMongoDB,
stop:database==="POSTGRESQL"?stopPostgresql:stopMongoDB,
models:database==="POSTGRESQL"?postgresql.models:mongodb.models,
manager:database==="POSTGRESQL"?postgresql:mongodb,
}
};
Loading

0 comments on commit d7411c2

Please sign in to comment.