0.1.0 • Published 8 months ago

@ikualo/lib-ms-dal v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

lib-ms-dal

lib-ms-dal is a library that makes it easier to work with the DAL microservice in the Íkualo Microservices Ecosystem. As many microservices need to connect to the DAL, this library encapsulates all of that logic for the services. This ensures all users of the DAL make the correct requests.

Getting Started

This library is expected to work withing a Nest.js environment.

Installing the Library

Before using the library, we need to install it. We'll use npm for this example:

npm install @ikualo/lib-ms-dal@latest

Using the Library

First, we need to register the module that will expose the service with the DAL functions. We'll follow the Nest.js documentation for that.

// test.module.ts

import { Module } from "@nestjs/common";
import { DalModule } from "@ikualo/lib/ms/dal";

@Module({
    imports: [
        DalModule.register({
            urls: ["amqp://localhost:5672"],
            queue: "TEST_QUEUE_DAL",
            queueOptions: {
                durable: false,
            },
        }),
    ],
})
class TestModule {}

After this, the service DalService will be available to the module that imports our DalModule, via dependency injection. We'll create a TestService for the TestModule, to see the usage of the service.

// test.service.ts

@Injectable()
class TestService {
  constructor(private readonly dalService: DalService) {}

  createElement() {
    this.dalService.create({
      db: "test",
      collection: "fish",
      data: {
        name: "Mussolini",
        breed: "Red Carp",
    });
  }
}

We have created a method createElement which uses the DalService to create a red carp fish named Mussolini in the test database.