@uql/mongo
Advanced tools
Comparing version 0.4.83 to 0.4.84
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.4.83", | ||
"version": "0.4.84", | ||
"main": "index.js", | ||
@@ -25,3 +25,3 @@ "types": "index.d.ts", | ||
"@types/node": "^17.0.23", | ||
"@uql/core": "^0.4.83", | ||
"@uql/core": "^0.4.84", | ||
"copyfiles": "^2.4.1", | ||
@@ -28,0 +28,0 @@ "rimraf": "^3.0.2", |
@@ -58,4 +58,4 @@ # [uql](https://uql.io) · [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rogerpadilla/uql/blob/main/LICENSE) [![tests](https://github.com/rogerpadilla/uql/actions/workflows/tests.yml/badge.svg)](https://github.com/rogerpadilla/uql) [![coverage status](https://coveralls.io/repos/rogerpadilla/uql/badge.svg?branch=main)](https://coveralls.io/r/rogerpadilla/uql?branch=main) [![npm version](https://badge.fury.io/js/%40uql%2Fcore.svg)](https://badge.fury.io/js/%40uql%2Fcore) | ||
| `PostgreSQL` | `@uql/postgres` | | ||
| `MongoDB` | `@uql/mongo` | | ||
| `SQLite` | `@uql/sqlite` | | ||
| `MongoDB` | `@uql/mongo` | | ||
@@ -108,2 +108,4 @@ E.g. for `PostgreSQL` | ||
```ts | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity'; | ||
@@ -116,4 +118,4 @@ | ||
*/ | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
@@ -125,3 +127,3 @@ picture?: string; | ||
@Field({ reference: () => User }) | ||
creatorId?: number; | ||
creatorId?: string; | ||
} | ||
@@ -131,4 +133,4 @@ | ||
export class User { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
@@ -149,4 +151,4 @@ name?: string; | ||
export class MeasureUnitCategory { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
@@ -160,8 +162,8 @@ name?: string; | ||
export class MeasureUnit { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
name?: string; | ||
@Field({ reference: () => MeasureUnitCategory }) | ||
categoryId?: number; | ||
categoryId?: string; | ||
@ManyToOne({ cascade: 'persist' }) | ||
@@ -173,4 +175,4 @@ category?: MeasureUnitCategory; | ||
export class Item { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
@@ -188,4 +190,4 @@ name?: string; | ||
export class Tag { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field() | ||
@@ -199,8 +201,8 @@ name?: string; | ||
export class ItemTag { | ||
@Id() | ||
id?: number; | ||
@Id({ onInsert: uuidv4 }) | ||
id?: string; | ||
@Field({ reference: () => Item }) | ||
itemId?: number; | ||
itemId?: string; | ||
@Field({ reference: () => Tag }) | ||
tagId?: number; | ||
tagId?: string; | ||
} | ||
@@ -265,2 +267,3 @@ ``` | ||
const querier = await getQuerier(); | ||
await querier.transaction(async () => { | ||
@@ -290,2 +293,3 @@ if (confirmation.action === 'signup') { | ||
const querier = await getQuerier(); | ||
try { | ||
@@ -341,23 +345,4 @@ await querier.beginTransaction(); | ||
app | ||
// ... | ||
.use( | ||
'/api', | ||
// this will generate REST APIs for the entities. | ||
querierMiddleware({ | ||
// all entities will be automatically exposed unless | ||
// 'include' or 'exclude' options are provided. | ||
exclude: [Confirmation], | ||
// `augmentQuery` callback allows to extend all then queries that are requested to the API, | ||
// so it is a good place to add additional filters to the queries, | ||
// e.g. for multi tenant apps. | ||
augmentQuery: <E>(meta: EntityMeta<E>, qm: Query<E>, req: express.Request): Query<E> => { | ||
// ensure the user can only see the data that belongs to his company. | ||
qm.$filter = augmentFilter(meta, qm.$filter, { companyId: req.identity.companyId } as QueryFilter<E>); | ||
return qm; | ||
}, | ||
}) | ||
); | ||
// this will generate REST APIs for the entities. | ||
app.use('/api', querierMiddleware()); | ||
``` | ||
@@ -364,0 +349,0 @@ |
Sorry, the diff of this file is not supported yet
96424
368