@e22m4u/js-repository-mongodb-adapter 0.5.6 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/cjs/index.cjs +843 -37
- package/package.json +2 -2
- package/src/mongodb-adapter.js +18 -4
- package/src/mongodb-adapter.spec.js +361 -147
- package/src/utils/index.js +3 -0
- package/src/utils/model-name-to-collection-name.js +26 -0
- package/src/utils/model-name-to-collection-name.spec.js +89 -0
- package/src/utils/pluralize.js +63 -0
- package/src/utils/pluralize.spec.js +110 -0
- package/src/utils/to-camel-case.js +18 -0
- package/src/utils/to-camel-case.spec.js +75 -0
package/README.md
CHANGED
|
@@ -26,10 +26,10 @@ npm install @e22m4u/js-repository-mongodb-adapter
|
|
|
26
26
|
```js
|
|
27
27
|
import {DatabaseSchema} from '@e22m4u/js-repository';
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const dbs = new DatabaseSchema();
|
|
30
30
|
|
|
31
31
|
// объявление источника
|
|
32
|
-
|
|
32
|
+
dbs.defineDatasource({
|
|
33
33
|
name: 'myMongo', // название источника
|
|
34
34
|
adapter: 'mongodb', // имя адаптера
|
|
35
35
|
// параметры
|
|
@@ -39,7 +39,7 @@ schema.defineDatasource({
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// объявление модели
|
|
42
|
-
|
|
42
|
+
dbs.defineModel({
|
|
43
43
|
name: 'user', // название модели
|
|
44
44
|
datasource: 'myMongo', // используемый источник (см. выше)
|
|
45
45
|
properties: { // поля модели
|
|
@@ -49,7 +49,7 @@ schema.defineModel({
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
// получаем репозиторий по названию модели и создаем запись
|
|
52
|
-
const userRep =
|
|
52
|
+
const userRep = dbs.getRepository('user');
|
|
53
53
|
const user = await userRep.create({name: 'John', surname: 'Doe'});
|
|
54
54
|
|
|
55
55
|
console.log(user);
|