@uql/core 0.4.81 → 0.4.84
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 +36 -51
- package/dialect/abstractSqlDialect-spec.d.ts +49 -0
- package/dialect/abstractSqlDialect-spec.js +765 -0
- package/dialect/mysqlDialect.spec.d.ts +6 -0
- package/dialect/mysqlDialect.spec.js +33 -0
- package/dialect/postgresDialect.spec.d.ts +1 -0
- package/dialect/postgresDialect.spec.js +139 -0
- package/dialect/sqliteDialect.spec.d.ts +1 -0
- package/dialect/sqliteDialect.spec.js +12 -0
- package/entity/decorator/definition.js +18 -18
- package/entity/decorator/definition.spec.d.ts +1 -0
- package/entity/decorator/definition.spec.js +725 -0
- package/entity/decorator/relation.spec.d.ts +1 -0
- package/entity/decorator/relation.spec.js +55 -0
- package/options.spec.d.ts +1 -0
- package/options.spec.js +50 -0
- package/package.json +3 -3
- package/querier/abstractQuerier-it.d.ts +41 -0
- package/querier/abstractQuerier-it.js +410 -0
- package/querier/abstractSqlQuerier-it.d.ts +9 -0
- package/querier/abstractSqlQuerier-it.js +19 -0
- package/querier/abstractSqlQuerier-spec.d.ts +53 -0
- package/querier/abstractSqlQuerier-spec.js +607 -0
- package/querier/decorator/injectQuerier.spec.d.ts +1 -0
- package/querier/decorator/injectQuerier.spec.js +108 -0
- package/querier/decorator/transactional.spec.d.ts +1 -0
- package/querier/decorator/transactional.spec.js +241 -0
- package/repository/genericRepository.spec.d.ts +1 -0
- package/repository/genericRepository.spec.js +86 -0
- package/test/entityMock.d.ts +180 -0
- package/test/entityMock.js +451 -0
- package/test/index.d.ts +3 -0
- package/test/index.js +7 -0
- package/test/it.util.d.ts +4 -0
- package/test/it.util.js +60 -0
- package/test/spec.util.d.ts +13 -0
- package/test/spec.util.js +54 -0
- package/type/entity.d.ts +15 -20
- package/type/entity.js +1 -1
- package/type/utility.d.ts +1 -1
- package/type/utility.js +1 -1
- package/util/dialect.util.spec.d.ts +1 -0
- package/util/dialect.util.spec.js +23 -0
- package/util/object.util.spec.d.ts +1 -0
- package/util/object.util.spec.js +26 -0
- package/util/sql.util.spec.d.ts +1 -0
- package/util/sql.util.spec.js +164 -0
- package/util/string.util.spec.d.ts +1 -0
- package/util/string.util.spec.js +26 -0
package/README.md
CHANGED
|
@@ -55,8 +55,8 @@ Given it is just a small library with serializable `JSON` syntax, the queries ca
|
|
|
55
55
|
| `MySQL` | `@uql/mysql` |
|
|
56
56
|
| `MariaDB` | `@uql/maria` |
|
|
57
57
|
| `PostgreSQL` | `@uql/postgres` |
|
|
58
|
-
| `SQLite` | `@uql/sqlite` |
|
|
59
58
|
| `MongoDB` | `@uql/mongo` |
|
|
59
|
+
| `SQLite` | `@uql/sqlite` |
|
|
60
60
|
|
|
61
61
|
E.g. for `PostgreSQL`
|
|
62
62
|
|
|
@@ -86,17 +86,17 @@ Initialization should be done once (e.g. in one of the bootstrap files of your a
|
|
|
86
86
|
import { setOptions } from '@uql/core';
|
|
87
87
|
import { PgQuerierPool } from '@uql/postgres';
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
89
|
+
const querierPool = new PgQuerierPool(
|
|
90
|
+
{
|
|
91
|
+
host: 'localhost',
|
|
92
|
+
user: 'theUser',
|
|
93
|
+
password: 'thePassword',
|
|
94
|
+
database: 'theDatabase',
|
|
95
|
+
},
|
|
96
|
+
console.log
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
setOptions({ querierPool });
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
## <a name="entities"></a> Entities
|
|
@@ -104,6 +104,8 @@ setOptions({
|
|
|
104
104
|
Take any dump class (aka DTO) and annotate it with the decorators from `'@uql/core/entity'`.
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
108
|
+
|
|
107
109
|
import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity';
|
|
108
110
|
|
|
109
111
|
@Entity()
|
|
@@ -111,21 +113,21 @@ export class Profile {
|
|
|
111
113
|
/**
|
|
112
114
|
* primary key
|
|
113
115
|
*/
|
|
114
|
-
@Id()
|
|
115
|
-
id?:
|
|
116
|
+
@Id({ onInsert: uuidv4 })
|
|
117
|
+
id?: string;
|
|
116
118
|
@Field()
|
|
117
119
|
picture?: string;
|
|
118
120
|
/**
|
|
119
121
|
* foreign-keys are really simple to specify.
|
|
120
122
|
*/
|
|
121
123
|
@Field({ reference: () => User })
|
|
122
|
-
creatorId?:
|
|
124
|
+
creatorId?: string;
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
@Entity()
|
|
126
128
|
export class User {
|
|
127
|
-
@Id()
|
|
128
|
-
id?:
|
|
129
|
+
@Id({ onInsert: uuidv4 })
|
|
130
|
+
id?: string;
|
|
129
131
|
@Field()
|
|
130
132
|
name?: string;
|
|
131
133
|
@Field()
|
|
@@ -141,8 +143,8 @@ export class User {
|
|
|
141
143
|
|
|
142
144
|
@Entity()
|
|
143
145
|
export class MeasureUnitCategory {
|
|
144
|
-
@Id()
|
|
145
|
-
id?:
|
|
146
|
+
@Id({ onInsert: uuidv4 })
|
|
147
|
+
id?: string;
|
|
146
148
|
@Field()
|
|
147
149
|
name?: string;
|
|
148
150
|
@OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.category })
|
|
@@ -151,20 +153,20 @@ export class MeasureUnitCategory {
|
|
|
151
153
|
|
|
152
154
|
@Entity()
|
|
153
155
|
export class MeasureUnit {
|
|
154
|
-
@Id()
|
|
155
|
-
id?:
|
|
156
|
+
@Id({ onInsert: uuidv4 })
|
|
157
|
+
id?: string;
|
|
156
158
|
@Field()
|
|
157
159
|
name?: string;
|
|
158
160
|
@Field({ reference: () => MeasureUnitCategory })
|
|
159
|
-
categoryId?:
|
|
161
|
+
categoryId?: string;
|
|
160
162
|
@ManyToOne({ cascade: 'persist' })
|
|
161
163
|
category?: MeasureUnitCategory;
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
@Entity()
|
|
165
167
|
export class Item {
|
|
166
|
-
@Id()
|
|
167
|
-
id?:
|
|
168
|
+
@Id({ onInsert: uuidv4 })
|
|
169
|
+
id?: string;
|
|
168
170
|
@Field()
|
|
169
171
|
name?: string;
|
|
170
172
|
@Field()
|
|
@@ -177,8 +179,8 @@ export class Item {
|
|
|
177
179
|
|
|
178
180
|
@Entity()
|
|
179
181
|
export class Tag {
|
|
180
|
-
@Id()
|
|
181
|
-
id?:
|
|
182
|
+
@Id({ onInsert: uuidv4 })
|
|
183
|
+
id?: string;
|
|
182
184
|
@Field()
|
|
183
185
|
name?: string;
|
|
184
186
|
@ManyToMany({ entity: () => Item, mappedBy: (item) => item.tags })
|
|
@@ -187,12 +189,12 @@ export class Tag {
|
|
|
187
189
|
|
|
188
190
|
@Entity()
|
|
189
191
|
export class ItemTag {
|
|
190
|
-
@Id()
|
|
191
|
-
id?:
|
|
192
|
+
@Id({ onInsert: uuidv4 })
|
|
193
|
+
id?: string;
|
|
192
194
|
@Field({ reference: () => Item })
|
|
193
|
-
itemId?:
|
|
195
|
+
itemId?: string;
|
|
194
196
|
@Field({ reference: () => Tag })
|
|
195
|
-
tagId?:
|
|
197
|
+
tagId?: string;
|
|
196
198
|
}
|
|
197
199
|
```
|
|
198
200
|
|
|
@@ -252,6 +254,7 @@ import { getQuerier } from '@uql/core';
|
|
|
252
254
|
|
|
253
255
|
async function confirm(confirmation: Confirmation): Promise<void> {
|
|
254
256
|
const querier = await getQuerier();
|
|
257
|
+
|
|
255
258
|
await querier.transaction(async () => {
|
|
256
259
|
if (confirmation.action === 'signup') {
|
|
257
260
|
await querier.insertOne(User, {
|
|
@@ -276,6 +279,7 @@ That ▲ can also be implemented as this ▼ (for more granular control)
|
|
|
276
279
|
```ts
|
|
277
280
|
async function confirm(confirmation: Confirmation): Promise<void> {
|
|
278
281
|
const querier = await getQuerier();
|
|
282
|
+
|
|
279
283
|
try {
|
|
280
284
|
await querier.beginTransaction();
|
|
281
285
|
if (confirmation.action === 'signup') {
|
|
@@ -326,27 +330,8 @@ import { querierMiddleware } from '@uql/express';
|
|
|
326
330
|
|
|
327
331
|
const app = express();
|
|
328
332
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
.use(
|
|
332
|
-
'/api',
|
|
333
|
-
|
|
334
|
-
// this will generate REST APIs for the entities.
|
|
335
|
-
querierMiddleware({
|
|
336
|
-
// all entities will be automatically exposed unless
|
|
337
|
-
// 'include' or 'exclude' options are provided.
|
|
338
|
-
exclude: [Confirmation],
|
|
339
|
-
|
|
340
|
-
// `augmentQuery` callback allows to extend all then queries that are requested to the API,
|
|
341
|
-
// so it is a good place to add additional filters to the queries,
|
|
342
|
-
// e.g. for multi tenant apps.
|
|
343
|
-
augmentQuery: <E>(meta: EntityMeta<E>, qm: Query<E>, req: express.Request): Query<E> => {
|
|
344
|
-
// ensure the user can only see the data that belongs to his company.
|
|
345
|
-
qm.$filter = augmentFilter(meta, qm.$filter, { companyId: req.identity.companyId } as QueryFilter<E>);
|
|
346
|
-
return qm;
|
|
347
|
-
},
|
|
348
|
-
})
|
|
349
|
-
);
|
|
333
|
+
// this will generate REST APIs for the entities.
|
|
334
|
+
app.use('/api', querierMiddleware());
|
|
350
335
|
```
|
|
351
336
|
|
|
352
337
|
## <a name="client"></a> Easily call the generated REST APIs from the Client
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Spec } from '@uql/core/test';
|
|
2
|
+
import { AbstractSqlDialect } from './abstractSqlDialect';
|
|
3
|
+
export declare abstract class AbstractSqlDialectSpec implements Spec {
|
|
4
|
+
readonly dialect: AbstractSqlDialect;
|
|
5
|
+
constructor(dialect: AbstractSqlDialect);
|
|
6
|
+
shouldBeValidEscapeCharacter(): void;
|
|
7
|
+
shouldBeginTransaction(): void;
|
|
8
|
+
shouldInsertMany(): void;
|
|
9
|
+
shouldInsertOne(): void;
|
|
10
|
+
shouldInsertWithOnInsertId(): void;
|
|
11
|
+
shouldInsertManyWithSpecifiedIdsAndOnInsertIdAsDefault(): void;
|
|
12
|
+
shouldUpdate(): void;
|
|
13
|
+
shouldFind(): void;
|
|
14
|
+
shouldBeSecure(): void;
|
|
15
|
+
shouldFind$and(): void;
|
|
16
|
+
shouldFind$or(): void;
|
|
17
|
+
shouldFind$not(): void;
|
|
18
|
+
shouldFind$nor(): void;
|
|
19
|
+
shouldFind$orAnd$and(): void;
|
|
20
|
+
shouldFindSingle$filter(): void;
|
|
21
|
+
shouldFindMultipleComparisonOperators(): void;
|
|
22
|
+
shouldFind$ne(): void;
|
|
23
|
+
shouldFindIsNull(): void;
|
|
24
|
+
shouldFind$in(): void;
|
|
25
|
+
shouldFind$nin(): void;
|
|
26
|
+
shouldFind$projectFields(): void;
|
|
27
|
+
shouldFind$projectOneToOne(): void;
|
|
28
|
+
shouldFind$projectManyToOne(): void;
|
|
29
|
+
shouldFind$projectWithAllFieldsAndSpecificFieldsAndFilter(): void;
|
|
30
|
+
shouldVirtualField(): void;
|
|
31
|
+
shouldFind$projectDeep(): void;
|
|
32
|
+
shouldFind$group(): void;
|
|
33
|
+
shouldFind$limit(): void;
|
|
34
|
+
shouldFind$skip(): void;
|
|
35
|
+
shouldFind$project(): void;
|
|
36
|
+
shouldDelete(): void;
|
|
37
|
+
shouldFind$projectRaw(): void;
|
|
38
|
+
shouldFind$filterRaw(): void;
|
|
39
|
+
shouldFind$startsWith(): void;
|
|
40
|
+
shouldFind$istartsWith(): void;
|
|
41
|
+
shouldFind$endsWith(): void;
|
|
42
|
+
shouldFind$iendsWith(): void;
|
|
43
|
+
shouldFind$includes(): void;
|
|
44
|
+
shouldFind$iincludes(): void;
|
|
45
|
+
shouldFind$like(): void;
|
|
46
|
+
shouldFind$ilike(): void;
|
|
47
|
+
shouldFind$regex(): void;
|
|
48
|
+
shouldFind$text(): void;
|
|
49
|
+
}
|