https://github.com/tripolskypetr/node-basecrud-service
The generic repository pattern implementation for NodeJS, aka BaseCRUD
https://github.com/tripolskypetr/node-basecrud-service
appwrite appwrite-database basecrud generic nodejs repository repository-pattern solid
Last synced: 7 months ago
JSON representation
The generic repository pattern implementation for NodeJS, aka BaseCRUD
- Host: GitHub
- URL: https://github.com/tripolskypetr/node-basecrud-service
- Owner: tripolskypetr
- License: mit
- Created: 2024-11-21T11:13:41.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-11-27T18:21:06.000Z (11 months ago)
- Last Synced: 2025-01-23T22:34:13.406Z (9 months ago)
- Topics: appwrite, appwrite-database, basecrud, generic, nodejs, repository, repository-pattern, solid
- Language: TypeScript
- Homepage: https://github.com/react-declarative/react-declarative
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-basecrud-service
> The generic repository pattern implementation for NodeJS, aka `BaseCRUD`
## Code sample
**BaseCrud.ts**
```typescript
export const BaseCrud = factory(
class {
protected readonly appwriteService = inject(TYPES.appwriteService);
protected readonly loggerService = inject(TYPES.loggerService);constructor(public name: string, public collectionId: string) {}
protected async findAll() {
this.loggerService.log(`${this.name} findAll`);
return await resolveDocuments(listDocuments(this.collectionId));
};protected async findById(id: string) {
this.loggerService.log(`${this.name} findById`, { id });
return await this.appwriteService.databases.getDocument(
CC_APPWRITE_DATABASE_ID,
this.collectionId,
id,
);
};protected async create(dto: unknown) {
this.loggerService.log(`${this.name} create`, { dto });
return await this.appwriteService.databases.createDocument(
CC_APPWRITE_DATABASE_ID,
this.collectionId,
this.appwriteService.createId(),
dto,
);
};protected async update(id: string, dto: unknown) {
this.loggerService.log(`${this.name} update`, { id, dto });
return await this.appwriteService.databases.updateDocument(
CC_APPWRITE_DATABASE_ID,
this.collectionId,
id,
dto,
);
};protected async remove(id: string) {
this.loggerService.log(`${this.name} remove`, { id });
return await this.appwriteService.databases.deleteDocument(
CC_APPWRITE_DATABASE_ID,
this.collectionId,
id,
);
};
}
);
```**TodoDbService.ts**
```typescript
export class TodoDbService extends BaseCrud("todoDbService", CC_APPWRITE_TODO_COLLECTION_ID) {public findAll = async () => {
return await super.findAll();
};public findById = async (id: string) => {
return await super.findById(id);
};public create = async (dto: ITodoDto) => {
return await super.create(dto);
};public update = async (id: string, dto: ITodoDto) => {
return await super.update(id, dto);
};public remove = async (id: string) => {
return await super.remove(id);
};
};export default TodoDbService;
```