Реализация репозитория для работы с базами данных

e22m4u d1093b4930 chore: updates README.md 2 years ago
.husky 711475680a chore: adds api documentation 2 years ago
docs d1093b4930 chore: updates README.md 2 years ago
src e90312d348 fix: tests of hasMany relation, relation typings and README.md 2 years ago
.c8rc dbff18d833 chore: initial commit 2 years ago
.commitlintrc dbff18d833 chore: initial commit 2 years ago
.editorconfig dbff18d833 chore: initial commit 2 years ago
.eslintignore 711475680a chore: adds api documentation 2 years ago
.eslintrc.cjs 85139bcc41 chore: adds *.d.ts 2 years ago
.gitignore dbff18d833 chore: initial commit 2 years ago
.mocharc.cjs dbff18d833 chore: initial commit 2 years ago
.prettierrc dbff18d833 chore: initial commit 2 years ago
LICENSE dbff18d833 chore: initial commit 2 years ago
README.md d1093b4930 chore: updates README.md 2 years ago
mocha.setup.js dbff18d833 chore: initial commit 2 years ago
package.json 711475680a chore: adds api documentation 2 years ago
tsconfig.json 771d9e379e chore: renames to @e22m4u/js-repository and fixes d.ts files 2 years ago
typedoc.json 711475680a chore: adds api documentation 2 years ago

README.md

@e22m4u/js-repository

Модуль для работы с базами данных для Node.js

Установка

npm install @e22m4u/js-repository

Опционально устанавливаем адаптер.

описание
memory виртуальная база в памяти процесса (не требует установки)
mongodb MongoDB - система управления NoSQL базами (установка)

Пример

Определение источника данных, модели и добавление нового документа в коллекцию.

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

// создание экземпляра схемы
const schema = new Schema();

// определение источника "myMemory"
schema.defineDatasource({
  name: 'myMemory', // название нового источника
  adapter: 'memory', // выбранный адаптер
});

// определение модели "country"
schema.defineModel({
  name: 'country', // название новой модели
  datasource: 'myMemory', // выбранный источник
  properties: { // поля модели
    name: DataType.STRING, // поле "name" типа "string"
    population: DataType.NUMBER, // поле "population" типа "number"
  },
})

// получение репозитория для модели "country"
const countryRep = schema.getRepository('country');

// добавление нового документа в коллекцию "country"
const country = await countryRep.create({
  name: 'Russia',
  population: 143400000,
});

// вывод результата
console.log(country);
// {
//   "id": 1,
//   "name": "Russia",
//   "population": 143400000,
// }

Тесты

npm run test

Лицензия

MIT