Socket
Socket
Sign inDemoInstall

@e22m4u/js-repository-mongodb-adapter

Package Overview
Dependencies
221
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @e22m4u/js-repository-mongodb-adapter

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


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@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'
port27017
database'database'
usernameundefined
passwordundefined

Пример:

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

Keywords

FAQs

Last updated on 16 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc