Skip to content

Commit

Permalink
added readme.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrahim354 committed Jul 8, 2022
1 parent 6cdbefe commit aae0b69
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/Database/README.md
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.

0 comments on commit aae0b69

Please sign in to comment.