Skip to content

Commit b257388

Browse files
committed
feat(pkg): expose model instance
1 parent 9b026f1 commit b257388

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ const task = await TaskModel.create({
9696
const task = await TaskModel.findOne({ id: 'cbdabs-29232323-msasd'});
9797
```
9898

99+
5. You can also use the underlying ORM model and instance methods
100+
101+
```typescript
102+
// create task
103+
const filter = { };
104+
const countTasks = await TaskModel.model.countDocuments(filter);
105+
106+
```
107+
99108
## 🫶 Projects using this package
100109
See the projects using this package in action.
101110
- [Fractal Js](https://github.com/fractalerp/fractal-js)

active_record.ts

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { ActiveRecordError } from "./lib/active_record_error";
99
export class ActiveRecord<T> implements ActiveRecordInterface<T> {
1010
private nosqlActiveRecord!: NoSqlActiveRecord<T>;
1111
private relationalActiveRecord!: RelationalActiveRecord<T>;
12-
13-
// TODO read database type from memory
1412
private databaseType = DatabaseType.NOSQL;
1513

1614
constructor(modelName: string, schema: Record<string, SchemaProperty>, databaseType = DatabaseType.NOSQL) {

nosql/nosql_active_record.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { NoSQLActiveRecordInterface } from "./nosql_active_record_interface";
1010
import DatabaseManagementSystem from "./../database/dms";
1111

1212
export class NoSqlActiveRecord<T> implements NoSQLActiveRecordInterface<T> {
13-
private model: Model<T>;
13+
public model: Model<T>;
1414
private dbms: DatabaseManagementSystem = new DatabaseManagementSystem();
1515

1616

@@ -22,7 +22,7 @@ export class NoSqlActiveRecord<T> implements NoSQLActiveRecordInterface<T> {
2222
this.model =
2323
process.env.NODE_ENV !== "test"
2424
? this.dbms.nosqlDB.database.model<T>(modelName, new Schema(mongoSchema as any))
25-
: model<T>(modelName, new Schema(mongoSchema as any)) // allow for
25+
: model<T>(modelName, new Schema(mongoSchema as any)) // allow for test
2626
}
2727

2828
async find(query: any): Promise<T[]> {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@fractalerp/active-record-js",
33
"appName": "Active Record Js",
4-
"version": "1.0.14",
4+
"version": "1.0.16",
55
"description": "Responsible for representing business data",
66
"author": "Acellam Guy <[email protected]>",
77
"keywords": [

relational/relational_active_record.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { RelationalActiveRecordInterface } from "./relational_active_record_inte
55

66
export class RelationalActiveRecord<T> implements RelationalActiveRecordInterface<T> {
77
private sequelize!: Sequelize;
8-
private model: typeof Model;
8+
public model: typeof Model;
99

1010
constructor(modelName: string, schema: Record<string, SchemaProperty>) {
1111
// TODO get global sequilize instance from memory

0 commit comments

Comments
 (0)