MongoDB адаптер для @e22m4u/js-repository

e22m4u 49bdc6b94d chore: upgrades @e22m4u/js-repository to 0.0.34 2 years ago
.husky 9e8d810694 chore: initial commit 2 years ago
src 61f977c121 chore: improve tests 2 years ago
.c8rc 9e8d810694 chore: initial commit 2 years ago
.commitlintrc 9e8d810694 chore: initial commit 2 years ago
.editorconfig 9e8d810694 chore: initial commit 2 years ago
.eslintrc.cjs 9e8d810694 chore: initial commit 2 years ago
.gitignore 9e8d810694 chore: initial commit 2 years ago
.mocharc.cjs 9e8d810694 chore: initial commit 2 years ago
.prettierrc 9e8d810694 chore: initial commit 2 years ago
LICENSE 9e8d810694 chore: initial commit 2 years ago
README.md f72992a8cf chore: updates README.md 2 years ago
mocha.setup.js 9e8d810694 chore: initial commit 2 years ago
package.json 49bdc6b94d chore: upgrades @e22m4u/js-repository to 0.0.34 2 years ago
setup.sh 9e8d810694 chore: initial commit 2 years ago
test.env 9e8d810694 chore: initial commit 2 years ago

README.md

@e22m4u/js-repository-mongodb-adapter

MongoDB адаптер для @e22m4u/js-repository

Установка

npm install @e22m4u/js-repository-mongodb-adapter

требует пакет js-repository

Параметры

Все указанные параметры опциональны:

название значение по умолчанию
protocol 'mongodb'
host '127.0.0.1'
port 27017
database 'database'
username undefined
password undefined

Пример:

import {Schema} from '@e22m4u/js-repository';

const schema = new Schema();

// объявление источника
schema.defineDatasource({
  name: 'myMongo', // название источника
  adapter: 'mongodb', // имя адаптера
  // параметры
  host: '127.0.0.1',
  port: 27017,
  database: 'myDatabase',
});

// объявление модели
schema.defineModel({
  name: 'user', // название модели
  datasource: 'myMongo', // используемый источник
  properties: { // поля модели
    name: 'string',
    surname: 'string',
  },
});

// получаем репозиторий по названию модели и создаем запись
const userRep = schema.getRepository('user');
const user = await userRep.create({name: 'John', surname: 'Doe'});

console.log(user);
// {
//   id: '64f3454e5e0893c13f9bf47e',
//   name: 'John',
//   surname: 'Doe',
// }

Тесты

Запуск контейнера mongo:latest скриптом setup.sh

./setup.sh

Выполнение тестов

npm run test

Лицензия

MIT