-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Fix] Fixing and Maintaining the database structure and exposed api…
…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
1 parent
5f4d586
commit d7411c2
Showing
20 changed files
with
312 additions
and
341 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
}; |
Oops, something went wrong.