5.1.10 • Published 5 years ago

@js-entity-repos/mongo v5.1.10

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
5 years ago

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 Entity interfaces.
    2. Construct the facade.
    3. Use the facade.

Entity Interface

import Entity from '@js-entity-repos/core/dist/types/Entity';

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

Construct the Facade

import factory from '@js-entity-repos/mongo/dist/factory';
import connectToDb from '@js-entity-repos/mongo/dist/utils/connectToDb';
import parseFilterId from '@js-entity-repos/mongo/dist/utils/parseFilterId';
import renameSortId from '@js-entity-repos/mongo/dist/utils/renameSortId';

const todosFacade = factory<TodoEntity>({
  // Optional property. Defaults to entityName.
  collectionName: 'todos',
  // Optional property to convert an entity to a DB document. Defaults to "utils/constructIdDocument".
  constructDocument: ({ id, ...patch}) => {
    return { _id: id, ...patch };
  },
  // Optional property to convert a DB document to an entity. Defaults to "utils/constructIdEntity".
  constructEntity: ({ _id, ...document }) => {
    return { id: _id, ...document };
  },
  // Optional property to convert an entity filter to a DB filter. Defaults to "utils/parseFilterId".
  constructFilter: (filter) => {
    return parseFilterId(filter);
  },
  // Optional property to convert an entity sort to a DB sort. Defaults to "utils/renameSortId".
  constructSort: (sort) => {
    return renameSortId(sort);
  },
  db: connectToDb({
    dbName: 'todoapp',
    url: 'mongodb://localhost:27017',
  }),
  // Optional property. Defaults to 10.
  defaultPaginationLimit: 10,
  entityName: 'todo',
});
5.1.10

5 years ago

5.1.9

5 years ago

5.1.8

5 years ago

5.1.7

6 years ago

5.1.6

6 years ago

5.1.5

6 years ago

5.1.4

6 years ago

5.1.3

6 years ago

5.1.2

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago