-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cdbefe
commit aae0b69
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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,52 @@ | ||
# Database Module | ||
This folder is a way of making the database usage inside of the API more modular. | ||
|
||
|
||
|
||
### Prototype : | ||
|
||
`Database(url, options)` | ||
|
||
Where: | ||
|
||
`url` is the connection string of the database that you would like to connect to. | ||
|
||
`options` is an object with the following keys: | ||
|
||
* `schema`: which is an object that contains a set of key-value pairs, key is the name of the record/table you want to add, value is a reference to the schema object that defines this record/table. | ||
|
||
-- the schema object defaults to all the schema objects that are defined to the system. | ||
|
||
-- more options will be added in the future for example different database types. | ||
|
||
### Basic usage : | ||
This is mostly how it's going to be used: | ||
|
||
```javascript | ||
const url = 'your-db-connection-url'; | ||
const db = new Database(url); | ||
|
||
// to find all users. | ||
const users = db.User.find(); | ||
```` | ||
|
||
In case of differenct schema in mind here's an example: | ||
```javascript | ||
const userSchema = require('./schema/userSchema'); | ||
const url = 'your-db-connection-url'; | ||
const db = new Database(url, { | ||
schema: { | ||
"User": userSchema | ||
} | ||
); | ||
// to find all users. | ||
const users = db.User.find(); | ||
```` | ||
### Goal: | ||
This approach is a way of making the database instantiatable for more functionality such as the multi-tenancy functionality instead of using the static | ||
database object provided by mongoose, we can use the modular opproach or a mix of both modular and static. | ||