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

e22m4u 005748697f chore: updates dependencies 3 months ago
.husky 297f901136 chore: adds CommonJS support 1 year ago
dist 8101935d32 chore: bumps @e22m4u/js-repository to 0.4.0 3 months ago
src 8101935d32 chore: bumps @e22m4u/js-repository to 0.4.0 3 months 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 dbdff10f1e chore: updates license 4 months ago
README.md 8101935d32 chore: bumps @e22m4u/js-repository to 0.4.0 3 months ago
build-cjs.js e207815a9a chore: updates esbuild config 1 year ago
eslint.config.js 5b403eaa6d chore: updates mongodb driver to 6.16.0 7 months ago
mocha.setup.js 512818fafd chore: upgrades dependencies 1 year ago
package.json 005748697f chore: updates dependencies 3 months ago
setup.sh 8021b929e8 chore: updates dependencies 4 months ago
test.env 8021b929e8 chore: updates dependencies 4 months ago

README.md

@e22m4u/js-repository-mongodb-adapter

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 {DatabaseSchema} from '@e22m4u/js-repository';

const dbs = new DatabaseSchema();

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

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

// получаем репозиторий по названию модели и создаем запись
const userRep = dbs.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