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

e22m4u 2a1af80647 chore: updates dependencies 8 months ago
.husky 297f901136 chore: adds CommonJS support 1 year ago
dist a460e9c0a9 chore: updates dependencies 11 months ago
src 4035dd8b8f chore: allows properties chaining 1 year 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
.gitignore 9e641d4ca8 chore: updates .gitignore 1 year ago
.mocharc.cjs 9e8d810694 chore: initial commit 2 years ago
.prettierrc 9e8d810694 chore: initial commit 2 years ago
LICENSE c18de00309 chore: updates LICENSE 1 year ago
README-ru.md 3e146a9751 chore: adds english translation 11 months ago
README.md 3e146a9751 chore: adds english translation 11 months ago
build-cjs.js e207815a9a chore: updates esbuild config 1 year ago
eslint.config.js aeea11fe96 chore: upgrades dependencies 1 year ago
mocha.setup.js 512818fafd chore: upgrades dependencies 1 year ago
package.json 2a1af80647 chore: updates dependencies 8 months ago
setup.sh 9e8d810694 chore: initial commit 2 years ago
test.env 9e8d810694 chore: initial commit 2 years ago

README-ru.md

@e22m4u/js-repository-mongodb-adapter

English | Русский

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

Установка

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

Параметры

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

название значение по умолчанию
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