Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

js-entity-repos/mongo

Repository files navigation

mongo

A concrete implementation of js-entity-repos for mongo.

Usage

  1. Install it with npm i @js-entity-repos/mongo.
  2. For each entity you will need to do the following.
    1. Create Id and Entity interfaces.
    2. Create a facade config.
    3. Construct the facade with the config and interfaces.
    4. Use the facade.

Id and Entity Interface

export interface TodoId {
  readonly id: string;
}

export interface TodoEntity extends TodoId {
  readonly description: string;
  readonly completed: boolean;
}

Facade Config

import facade from '@js-entity-repos/mongo/dist/utils/connectToCollection';

const todoFacadeConfig = {
  collection: connectToCollection({
    collectionName: 'todos',
    dbName: 'todoapp',
    url: 'mongodb://localhost:27017',
  }),
  entityName: 'todo',
};

Construct the Facade

import facade from '@js-entity-repos/mongo/dist/facade';

const todosFacade = facade<TodoId, TodoEntity>(todoFacadeConfig);