Skip to content

Commit 9b026f1

Browse files
committed
docs(pkg): add basic developer guide
1 parent d7b91a9 commit 9b026f1

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#PRODUCTION
2+
RDBMS_DATABASE_URI="mysql://DATBASE_USER:DATABASE_PASSWORD@DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
3+
NOSQL_DATABASE_URI="mongodb://DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
4+
NOSQL_DATABASE_ADAPTER="mongodb"
5+
API_BASE='/v1/'

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,87 @@ A library responsible for representing business data.
2121

2222
This library follows the `Active Record Pattern` by building a wrapper on top of popular orm such as [Mongoose](https://www.npmjs.com/package/mongoose) and [Sequelize](https://www.npmjs.com/package/sequelize) to support all kinds of databases
2323

24+
## ⚙️ How to use the package in project
25+
1. You should create the following environment variables in your node project.
26+
```env
27+
RDBMS_DATABASE_URI="mysql://DATBASE_USER:DATABASE_PASSWORD@DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
28+
NOSQL_DATABASE_URI="mongodb://DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
29+
NOSQL_DATABASE_ADAPTER="mongodb"
30+
```
31+
2. Once the variables have been set. You should create a model base on the active record `SchemaProperty`. See example below
32+
33+
```typescript
34+
import { ActiveRecord } from "@fractalerp/active-record-js"
35+
36+
export interface ITaskModelDocument {
37+
name: string;
38+
description: string;
39+
}
40+
41+
const TaskModelSchema = {
42+
name: {
43+
type: String,
44+
required: true,
45+
unique: true
46+
},
47+
description: {
48+
type: String,
49+
default: null
50+
}
51+
};
52+
53+
export const TaskModel = new ActiveRecord<ITaskModelDocument>("Task", TaskModelSchema);
54+
55+
```
56+
3. Then use its methods to perform data management. The following methods are supported;
57+
58+
|Method|Description|
59+
|------------------|-----------|
60+
|`find`|returns list of data objects|
61+
|`findOne`|returns one data item|
62+
|`create`|save item to the data store|
63+
|`update`|updates the record in the store|
64+
|`delete`|delete item from the data store|
2465

25-
## 🪲 Issues, suggestions and feature requests
26-
👩‍🚒 We are failing to get the published NPM package working. Someone can fix it and send a pull request.
66+
Since we support all kinds of databases. The following are the respective methods of the two kinds of databases.
67+
68+
This only applies to `NOSQL databases`
69+
70+
|Method|Description|
71+
|------------------|-----------|
72+
|`aggregate`|peform aggregate action based on a pipeline|
73+
|`index`|create an index in the document store|
74+
75+
This only applies to `Relational databases`
76+
77+
|Method|Description|
78+
|------------------|-----------|
79+
|`query`|create a raw `SQL` to send to database|
80+
|`beginTransaction`|start a transaction|
81+
|`commitTransaction`|persist a transaction|
82+
|`rollbackTransaction`|rollback a transaction|
83+
84+
Other than that, all the other ORM respective methods for `Sequelize` and `Mongoose` are supported by default.
85+
86+
4. Finally you can use the model to peform data action. See example.
87+
88+
```typescript
89+
// create task
90+
const task = await TaskModel.create({
91+
name: 'Use fractalerp active record js',
92+
description: 'Change all models'
93+
});
2794

28-
In the mean time, you can just include the module as part of the project and use it 🚀
95+
// Find one task
96+
const task = await TaskModel.findOne({ id: 'cbdabs-29232323-msasd'});
97+
```
98+
99+
## 🫶 Projects using this package
100+
See the projects using this package in action.
101+
- [Fractal Js](https://github.com/fractalerp/fractal-js)
102+
- [Fractalerp core](https://github.com/fractalerp/fractal-core)
103+
104+
## 🪲 Issues, suggestions and feature requests
29105

30106
We are actively maintaining this boilerplate, please report any issues or suggestion for improvement at https://github.com/fractalerp/active-record-js/issues
31107

0 commit comments

Comments
 (0)