0.0.19 • Published 3 years ago
@e22m4u/js-repository-mongodb-adapter v0.0.19
@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 {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
0.2.1
2 years ago
0.2.0
2 years ago
0.1.8
2 years ago
0.1.7
2 years ago
0.1.9
2 years ago
0.3.2
2 years ago
0.4.0
1 year ago
0.3.1
2 years ago
0.3.3
1 year ago
0.1.6
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.0
3 years ago
0.1.1
3 years ago
0.0.25
3 years ago
0.0.24
3 years ago
0.0.23
3 years ago
0.0.22
3 years ago
0.0.21
3 years ago
0.0.20
3 years ago
0.0.19
3 years ago
0.0.18
3 years ago
0.0.17
3 years ago
0.0.16
3 years ago
0.0.15
3 years ago
0.0.14
3 years ago