1.1.0 • Published 2 years ago

nestjs-notarealdb v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Nest.js Json Based DB.

release

You don't need to prepare DB. use json file.

  • simple wrapper of package mirkonasato/notarealdb for NestJS
  • Attention This is not for Production use.

  • only development use is prefer

Installation

npm install nestjs-notarealdb

Example module setup

import at app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ApplesModule } from './apples/apples.module';
import { NotARealDbModule } from 'nestjs-notarealdb';

@Module({
  imports: [
    ApplesModule,
    NotARealDbModule.forRoot({
      dataDirName: 'store' // anyting you want. default 'data'
    })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Then, import at feature modules like this

import { Module } from '@nestjs/common';
import { ApplesService } from './apples.service';
import { ApplesController } from './apples.controller';
import { Apple } from '../shared/models/apple.model';
import { NotARealDbModule } from 'nestjs-notarealdb';

@Module({
  imports:[
    NotARealDbModule.forFeature([Apple])
  ],
  controllers: [
    ApplesController,
  ],
  providers: [ApplesService]
})
export class ApplesModule {}

service: @InjectCollection is need.

export class ApplesService {
  constructor(@InjectCollection(Apple) private readonly collection: Collection<Apple>) {
  }

  create(createAppleDto: CreateAppleDto) {
    return this.collection.create(createAppleDto)
  }

  findAll() {
    this.collection.list()
  }

  findOne(id: string) {
    return this.collection.get(id)
  }

.....................

}

License

The code is under MIT license. See the LICENSE file for details.