@e22m4u/js-repository 0.2.6 → 0.3.0
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 +79 -80
- package/dist/cjs/index.cjs +2023 -2093
- package/eslint.config.js +1 -1
- package/package.json +15 -12
- package/src/adapter/adapter-registry.spec.js +7 -7
- package/src/adapter/adapter.spec.js +11 -11
- package/src/adapter/builtin/memory-adapter.spec.js +537 -537
- package/src/adapter/decorator/data-sanitizing-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-transformation-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-validation-decorator.spec.js +5 -5
- package/src/adapter/decorator/default-values-decorator.spec.js +5 -5
- package/src/adapter/decorator/fields-filtering-decorator.spec.js +5 -5
- package/src/adapter/decorator/inclusion-decorator.spec.js +5 -5
- package/src/adapter/decorator/property-uniqueness-decorator.spec.js +5 -5
- package/src/{schema.d.ts → database-schema.d.ts} +2 -2
- package/src/{schema.js → database-schema.js} +2 -2
- package/src/database-schema.spec.ts +86 -0
- package/src/definition/model/model-data-transformer.js +3 -3
- package/src/definition/model/model-data-transformer.spec.js +93 -93
- package/src/definition/model/model-data-validator.js +2 -2
- package/src/definition/model/model-data-validator.spec.js +517 -531
- package/src/definition/model/model-definition-utils.js +3 -3
- package/src/definition/model/model-definition-utils.spec.js +345 -343
- package/src/definition/model/properties/index.d.ts +0 -1
- package/src/definition/model/properties/index.js +0 -1
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
- package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +36 -36
- package/src/filter/fields-clause-tool.spec.js +4 -4
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/relations/belongs-to-resolver.spec.js +166 -166
- package/src/relations/has-many-resolver.spec.js +281 -281
- package/src/relations/has-one-resolver.spec.js +281 -281
- package/src/relations/references-many-resolver.spec.js +92 -92
- package/src/repository/repository-registry.spec.js +10 -10
- package/src/repository/repository.spec.js +73 -73
- package/src/utils/is-promise.spec.js +1 -2
- package/src/utils/transform-promise.spec.js +0 -1
- package/src/definition/model/properties/empty-values-definer.d.ts +0 -23
- package/src/definition/model/properties/empty-values-definer.js +0 -66
- package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
- package/src/schema.spec.ts +0 -86
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {Schema} from '../../schema.js';
|
|
3
2
|
import {format} from '@e22m4u/js-format';
|
|
4
3
|
import {MemoryAdapter} from './memory-adapter.js';
|
|
5
4
|
import {DataType} from '../../definition/index.js';
|
|
5
|
+
import {DatabaseSchema} from '../../database-schema.js';
|
|
6
6
|
import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../../definition/index.js';
|
|
7
7
|
|
|
8
8
|
describe('MemoryAdapter', function () {
|
|
9
9
|
describe('_getTableOrCreate', function () {
|
|
10
10
|
it('returns an existing table or creates a new', function () {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const A =
|
|
11
|
+
const dbs = new DatabaseSchema();
|
|
12
|
+
dbs.defineModel({name: 'model'});
|
|
13
|
+
const A = dbs.getService(MemoryAdapter);
|
|
14
14
|
const table = A._getTableOrCreate('model');
|
|
15
15
|
expect(table).to.be.instanceof(Map);
|
|
16
16
|
const sameTable = A._getTableOrCreate('model');
|
|
@@ -18,12 +18,12 @@ describe('MemoryAdapter', function () {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('uses a model name to find a table, even a table name is specified', function () {
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const dbs = new DatabaseSchema();
|
|
22
|
+
dbs.defineModel({
|
|
23
23
|
name: 'myModel',
|
|
24
24
|
tableName: 'myTable',
|
|
25
25
|
});
|
|
26
|
-
const A =
|
|
26
|
+
const A = dbs.getService(MemoryAdapter);
|
|
27
27
|
const table = A._getTableOrCreate('myModel');
|
|
28
28
|
expect(table).to.be.instanceof(Map);
|
|
29
29
|
const sameTable = A._getTableOrCreate('myModel');
|
|
@@ -31,12 +31,12 @@ describe('MemoryAdapter', function () {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
it('stores a table by specified table name', function () {
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const dbs = new DatabaseSchema();
|
|
35
|
+
dbs.defineModel({
|
|
36
36
|
name: 'myModel',
|
|
37
37
|
tableName: 'myTable',
|
|
38
38
|
});
|
|
39
|
-
const A =
|
|
39
|
+
const A = dbs.getService(MemoryAdapter);
|
|
40
40
|
const table = A._getTableOrCreate('myModel');
|
|
41
41
|
expect(table).to.be.instanceof(Map);
|
|
42
42
|
const sameTable = A._tables.get('myTable');
|
|
@@ -46,9 +46,9 @@ describe('MemoryAdapter', function () {
|
|
|
46
46
|
|
|
47
47
|
describe('_genNextIdValue', function () {
|
|
48
48
|
it('returns an unique number identifier', function () {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const A =
|
|
49
|
+
const dbs = new DatabaseSchema();
|
|
50
|
+
dbs.defineModel({name: 'model'});
|
|
51
|
+
const A = dbs.getService(MemoryAdapter);
|
|
52
52
|
const id1 = A._genNextIdValue('model', DEF_PK);
|
|
53
53
|
const id2 = A._genNextIdValue('model', DEF_PK);
|
|
54
54
|
const id3 = A._genNextIdValue('model', DEF_PK);
|
|
@@ -60,16 +60,16 @@ describe('MemoryAdapter', function () {
|
|
|
60
60
|
|
|
61
61
|
describe('create', function () {
|
|
62
62
|
it('skips existing values when generating a new identifier for a default primary key', async function () {
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const dbs = new DatabaseSchema();
|
|
64
|
+
dbs.defineDatasource({
|
|
65
65
|
name: 'memory',
|
|
66
66
|
adapter: 'memory',
|
|
67
67
|
});
|
|
68
|
-
|
|
68
|
+
dbs.defineModel({
|
|
69
69
|
name: 'model',
|
|
70
70
|
datasource: 'memory',
|
|
71
71
|
});
|
|
72
|
-
const adapter = new MemoryAdapter(
|
|
72
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
73
73
|
const result1 = await adapter.create('model', {});
|
|
74
74
|
const result2 = await adapter.create('model', {});
|
|
75
75
|
const result3 = await adapter.create('model', {[DEF_PK]: 3});
|
|
@@ -81,12 +81,12 @@ describe('MemoryAdapter', function () {
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
it('skips existing values when generating a new identifier for a specified primary key', async function () {
|
|
84
|
-
const
|
|
85
|
-
|
|
84
|
+
const dbs = new DatabaseSchema();
|
|
85
|
+
dbs.defineDatasource({
|
|
86
86
|
name: 'memory',
|
|
87
87
|
adapter: 'memory',
|
|
88
88
|
});
|
|
89
|
-
|
|
89
|
+
dbs.defineModel({
|
|
90
90
|
name: 'model',
|
|
91
91
|
datasource: 'memory',
|
|
92
92
|
properties: {
|
|
@@ -96,7 +96,7 @@ describe('MemoryAdapter', function () {
|
|
|
96
96
|
},
|
|
97
97
|
},
|
|
98
98
|
});
|
|
99
|
-
const adapter = new MemoryAdapter(
|
|
99
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
100
100
|
const result1 = await adapter.create('model', {});
|
|
101
101
|
const result2 = await adapter.create('model', {});
|
|
102
102
|
const result3 = await adapter.create('model', {myId: 3});
|
|
@@ -108,12 +108,12 @@ describe('MemoryAdapter', function () {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('generates a new identifier when a value of a primary key has not provided', async function () {
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const dbs = new DatabaseSchema();
|
|
112
|
+
dbs.defineDatasource({
|
|
113
113
|
name: 'memory',
|
|
114
114
|
adapter: 'memory',
|
|
115
115
|
});
|
|
116
|
-
|
|
116
|
+
dbs.defineModel({
|
|
117
117
|
name: 'model',
|
|
118
118
|
datasource: 'memory',
|
|
119
119
|
properties: {
|
|
@@ -121,7 +121,7 @@ describe('MemoryAdapter', function () {
|
|
|
121
121
|
bar: DataType.NUMBER,
|
|
122
122
|
},
|
|
123
123
|
});
|
|
124
|
-
const adapter = new MemoryAdapter(
|
|
124
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
125
125
|
const input = {foo: 'string', bar: 10};
|
|
126
126
|
const created = await adapter.create('model', input);
|
|
127
127
|
const idValue = created[DEF_PK];
|
|
@@ -132,12 +132,12 @@ describe('MemoryAdapter', function () {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it('generates a new identifier when a value of a primary key is undefined', async function () {
|
|
135
|
-
const
|
|
136
|
-
|
|
135
|
+
const dbs = new DatabaseSchema();
|
|
136
|
+
dbs.defineDatasource({
|
|
137
137
|
name: 'memory',
|
|
138
138
|
adapter: 'memory',
|
|
139
139
|
});
|
|
140
|
-
|
|
140
|
+
dbs.defineModel({
|
|
141
141
|
name: 'model',
|
|
142
142
|
datasource: 'memory',
|
|
143
143
|
properties: {
|
|
@@ -145,7 +145,7 @@ describe('MemoryAdapter', function () {
|
|
|
145
145
|
bar: DataType.NUMBER,
|
|
146
146
|
},
|
|
147
147
|
});
|
|
148
|
-
const adapter = new MemoryAdapter(
|
|
148
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
149
149
|
const input = {
|
|
150
150
|
[DEF_PK]: undefined,
|
|
151
151
|
foo: 'string',
|
|
@@ -160,12 +160,12 @@ describe('MemoryAdapter', function () {
|
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
it('generates a new identifier when a value of a primary key is null', async function () {
|
|
163
|
-
const
|
|
164
|
-
|
|
163
|
+
const dbs = new DatabaseSchema();
|
|
164
|
+
dbs.defineDatasource({
|
|
165
165
|
name: 'memory',
|
|
166
166
|
adapter: 'memory',
|
|
167
167
|
});
|
|
168
|
-
|
|
168
|
+
dbs.defineModel({
|
|
169
169
|
name: 'model',
|
|
170
170
|
datasource: 'memory',
|
|
171
171
|
properties: {
|
|
@@ -173,7 +173,7 @@ describe('MemoryAdapter', function () {
|
|
|
173
173
|
bar: DataType.NUMBER,
|
|
174
174
|
},
|
|
175
175
|
});
|
|
176
|
-
const adapter = new MemoryAdapter(
|
|
176
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
177
177
|
const input = {
|
|
178
178
|
[DEF_PK]: null,
|
|
179
179
|
foo: 'string',
|
|
@@ -188,12 +188,12 @@ describe('MemoryAdapter', function () {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
it('generates a new identifier when a value of a primary key is an empty string', async function () {
|
|
191
|
-
const
|
|
192
|
-
|
|
191
|
+
const dbs = new DatabaseSchema();
|
|
192
|
+
dbs.defineDatasource({
|
|
193
193
|
name: 'memory',
|
|
194
194
|
adapter: 'memory',
|
|
195
195
|
});
|
|
196
|
-
|
|
196
|
+
dbs.defineModel({
|
|
197
197
|
name: 'model',
|
|
198
198
|
datasource: 'memory',
|
|
199
199
|
properties: {
|
|
@@ -201,7 +201,7 @@ describe('MemoryAdapter', function () {
|
|
|
201
201
|
bar: DataType.NUMBER,
|
|
202
202
|
},
|
|
203
203
|
});
|
|
204
|
-
const adapter = new MemoryAdapter(
|
|
204
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
205
205
|
const input = {
|
|
206
206
|
[DEF_PK]: '',
|
|
207
207
|
foo: 'string',
|
|
@@ -217,12 +217,12 @@ describe('MemoryAdapter', function () {
|
|
|
217
217
|
});
|
|
218
218
|
|
|
219
219
|
it('generates a new identifier when a value of a primary key is zero', async function () {
|
|
220
|
-
const
|
|
221
|
-
|
|
220
|
+
const dbs = new DatabaseSchema();
|
|
221
|
+
dbs.defineDatasource({
|
|
222
222
|
name: 'memory',
|
|
223
223
|
adapter: 'memory',
|
|
224
224
|
});
|
|
225
|
-
|
|
225
|
+
dbs.defineModel({
|
|
226
226
|
name: 'model',
|
|
227
227
|
datasource: 'memory',
|
|
228
228
|
properties: {
|
|
@@ -230,7 +230,7 @@ describe('MemoryAdapter', function () {
|
|
|
230
230
|
bar: DataType.NUMBER,
|
|
231
231
|
},
|
|
232
232
|
});
|
|
233
|
-
const adapter = new MemoryAdapter(
|
|
233
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
234
234
|
const input = {
|
|
235
235
|
[DEF_PK]: 0,
|
|
236
236
|
foo: 'string',
|
|
@@ -246,12 +246,12 @@ describe('MemoryAdapter', function () {
|
|
|
246
246
|
});
|
|
247
247
|
|
|
248
248
|
it('generates a new identifier for a primary key of a "number" type', async function () {
|
|
249
|
-
const
|
|
250
|
-
|
|
249
|
+
const dbs = new DatabaseSchema();
|
|
250
|
+
dbs.defineDatasource({
|
|
251
251
|
name: 'memory',
|
|
252
252
|
adapter: 'memory',
|
|
253
253
|
});
|
|
254
|
-
|
|
254
|
+
dbs.defineModel({
|
|
255
255
|
name: 'model',
|
|
256
256
|
datasource: 'memory',
|
|
257
257
|
properties: {
|
|
@@ -261,7 +261,7 @@ describe('MemoryAdapter', function () {
|
|
|
261
261
|
},
|
|
262
262
|
},
|
|
263
263
|
});
|
|
264
|
-
const adapter = new MemoryAdapter(
|
|
264
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
265
265
|
const result1 = await adapter.create('model', {});
|
|
266
266
|
const result2 = await adapter.create('model', {});
|
|
267
267
|
const result3 = await adapter.create('model', {});
|
|
@@ -271,12 +271,12 @@ describe('MemoryAdapter', function () {
|
|
|
271
271
|
});
|
|
272
272
|
|
|
273
273
|
it('generates a new identifier for a primary key of an "any" type', async function () {
|
|
274
|
-
const
|
|
275
|
-
|
|
274
|
+
const dbs = new DatabaseSchema();
|
|
275
|
+
dbs.defineDatasource({
|
|
276
276
|
name: 'memory',
|
|
277
277
|
adapter: 'memory',
|
|
278
278
|
});
|
|
279
|
-
|
|
279
|
+
dbs.defineModel({
|
|
280
280
|
name: 'model',
|
|
281
281
|
datasource: 'memory',
|
|
282
282
|
properties: {
|
|
@@ -286,7 +286,7 @@ describe('MemoryAdapter', function () {
|
|
|
286
286
|
},
|
|
287
287
|
},
|
|
288
288
|
});
|
|
289
|
-
const adapter = new MemoryAdapter(
|
|
289
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
290
290
|
const result1 = await adapter.create('model', {});
|
|
291
291
|
const result2 = await adapter.create('model', {});
|
|
292
292
|
const result3 = await adapter.create('model', {});
|
|
@@ -296,12 +296,12 @@ describe('MemoryAdapter', function () {
|
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
it('throws an error when generating a new value for a primary key of a "string" type', async function () {
|
|
299
|
-
const
|
|
300
|
-
|
|
299
|
+
const dbs = new DatabaseSchema();
|
|
300
|
+
dbs.defineDatasource({
|
|
301
301
|
name: 'memory',
|
|
302
302
|
adapter: 'memory',
|
|
303
303
|
});
|
|
304
|
-
|
|
304
|
+
dbs.defineModel({
|
|
305
305
|
name: 'model',
|
|
306
306
|
datasource: 'memory',
|
|
307
307
|
properties: {
|
|
@@ -311,7 +311,7 @@ describe('MemoryAdapter', function () {
|
|
|
311
311
|
},
|
|
312
312
|
},
|
|
313
313
|
});
|
|
314
|
-
const adapter = new MemoryAdapter(
|
|
314
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
315
315
|
const promise = adapter.create('model', {foo: 'string', bar: 10});
|
|
316
316
|
await expect(promise).to.be.rejectedWith(
|
|
317
317
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -323,12 +323,12 @@ describe('MemoryAdapter', function () {
|
|
|
323
323
|
});
|
|
324
324
|
|
|
325
325
|
it('throws an error when generating a new value for a primary key of a "boolean" type', async function () {
|
|
326
|
-
const
|
|
327
|
-
|
|
326
|
+
const dbs = new DatabaseSchema();
|
|
327
|
+
dbs.defineDatasource({
|
|
328
328
|
name: 'memory',
|
|
329
329
|
adapter: 'memory',
|
|
330
330
|
});
|
|
331
|
-
|
|
331
|
+
dbs.defineModel({
|
|
332
332
|
name: 'model',
|
|
333
333
|
datasource: 'memory',
|
|
334
334
|
properties: {
|
|
@@ -338,7 +338,7 @@ describe('MemoryAdapter', function () {
|
|
|
338
338
|
},
|
|
339
339
|
},
|
|
340
340
|
});
|
|
341
|
-
const adapter = new MemoryAdapter(
|
|
341
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
342
342
|
const promise = adapter.create('model', {foo: 'string', bar: 10});
|
|
343
343
|
await expect(promise).to.be.rejectedWith(
|
|
344
344
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -350,12 +350,12 @@ describe('MemoryAdapter', function () {
|
|
|
350
350
|
});
|
|
351
351
|
|
|
352
352
|
it('throws an error when generating a new value for a primary key of an "array" type', async function () {
|
|
353
|
-
const
|
|
354
|
-
|
|
353
|
+
const dbs = new DatabaseSchema();
|
|
354
|
+
dbs.defineDatasource({
|
|
355
355
|
name: 'memory',
|
|
356
356
|
adapter: 'memory',
|
|
357
357
|
});
|
|
358
|
-
|
|
358
|
+
dbs.defineModel({
|
|
359
359
|
name: 'model',
|
|
360
360
|
datasource: 'memory',
|
|
361
361
|
properties: {
|
|
@@ -366,7 +366,7 @@ describe('MemoryAdapter', function () {
|
|
|
366
366
|
},
|
|
367
367
|
},
|
|
368
368
|
});
|
|
369
|
-
const adapter = new MemoryAdapter(
|
|
369
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
370
370
|
const promise = adapter.create('model', {});
|
|
371
371
|
await expect(promise).to.be.rejectedWith(
|
|
372
372
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -378,12 +378,12 @@ describe('MemoryAdapter', function () {
|
|
|
378
378
|
});
|
|
379
379
|
|
|
380
380
|
it('throws an error when generating a new value for a primary key of an "object" type', async function () {
|
|
381
|
-
const
|
|
382
|
-
|
|
381
|
+
const dbs = new DatabaseSchema();
|
|
382
|
+
dbs.defineDatasource({
|
|
383
383
|
name: 'memory',
|
|
384
384
|
adapter: 'memory',
|
|
385
385
|
});
|
|
386
|
-
|
|
386
|
+
dbs.defineModel({
|
|
387
387
|
name: 'model',
|
|
388
388
|
datasource: 'memory',
|
|
389
389
|
properties: {
|
|
@@ -393,7 +393,7 @@ describe('MemoryAdapter', function () {
|
|
|
393
393
|
},
|
|
394
394
|
},
|
|
395
395
|
});
|
|
396
|
-
const adapter = new MemoryAdapter(
|
|
396
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
397
397
|
const promise = adapter.create('model', {});
|
|
398
398
|
await expect(promise).to.be.rejectedWith(
|
|
399
399
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -405,12 +405,12 @@ describe('MemoryAdapter', function () {
|
|
|
405
405
|
});
|
|
406
406
|
|
|
407
407
|
it('allows to specify an identifier value for a new item', async function () {
|
|
408
|
-
const
|
|
409
|
-
|
|
408
|
+
const dbs = new DatabaseSchema();
|
|
409
|
+
dbs.defineDatasource({
|
|
410
410
|
name: 'memory',
|
|
411
411
|
adapter: 'memory',
|
|
412
412
|
});
|
|
413
|
-
|
|
413
|
+
dbs.defineModel({
|
|
414
414
|
name: 'model',
|
|
415
415
|
datasource: 'memory',
|
|
416
416
|
properties: {
|
|
@@ -418,7 +418,7 @@ describe('MemoryAdapter', function () {
|
|
|
418
418
|
bar: DataType.NUMBER,
|
|
419
419
|
},
|
|
420
420
|
});
|
|
421
|
-
const adapter = new MemoryAdapter(
|
|
421
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
422
422
|
const idValue = 5;
|
|
423
423
|
const input = {foo: 'string', bar: 10};
|
|
424
424
|
const created = await adapter.create('model', {
|
|
@@ -432,19 +432,19 @@ describe('MemoryAdapter', function () {
|
|
|
432
432
|
});
|
|
433
433
|
|
|
434
434
|
it('throws an error if a given identifier value already exists', async function () {
|
|
435
|
-
const
|
|
436
|
-
|
|
435
|
+
const dbs = new DatabaseSchema();
|
|
436
|
+
dbs.defineDatasource({
|
|
437
437
|
name: 'memory',
|
|
438
438
|
adapter: 'memory',
|
|
439
439
|
});
|
|
440
|
-
|
|
440
|
+
dbs.defineModel({
|
|
441
441
|
name: 'model',
|
|
442
442
|
datasource: 'memory',
|
|
443
443
|
properties: {
|
|
444
444
|
foo: DataType.STRING,
|
|
445
445
|
},
|
|
446
446
|
});
|
|
447
|
-
const adapter = new MemoryAdapter(
|
|
447
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
448
448
|
const created = await adapter.create('model', {foo: 'string'});
|
|
449
449
|
const promise = adapter.create('model', created);
|
|
450
450
|
await expect(promise).to.be.rejectedWith(
|
|
@@ -456,12 +456,12 @@ describe('MemoryAdapter', function () {
|
|
|
456
456
|
});
|
|
457
457
|
|
|
458
458
|
it('sets default values if they are not provided for a new item', async function () {
|
|
459
|
-
const
|
|
460
|
-
|
|
459
|
+
const dbs = new DatabaseSchema();
|
|
460
|
+
dbs.defineDatasource({
|
|
461
461
|
name: 'memory',
|
|
462
462
|
adapter: 'memory',
|
|
463
463
|
});
|
|
464
|
-
|
|
464
|
+
dbs.defineModel({
|
|
465
465
|
name: 'model',
|
|
466
466
|
datasource: 'memory',
|
|
467
467
|
properties: {
|
|
@@ -475,7 +475,7 @@ describe('MemoryAdapter', function () {
|
|
|
475
475
|
},
|
|
476
476
|
},
|
|
477
477
|
});
|
|
478
|
-
const adapter = new MemoryAdapter(
|
|
478
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
479
479
|
const created = await adapter.create('model', {});
|
|
480
480
|
const idValue = created[DEF_PK];
|
|
481
481
|
const defaults = {foo: 10, bar: 'string'};
|
|
@@ -486,12 +486,12 @@ describe('MemoryAdapter', function () {
|
|
|
486
486
|
});
|
|
487
487
|
|
|
488
488
|
it('sets default values for properties provided with an undefined value', async function () {
|
|
489
|
-
const
|
|
490
|
-
|
|
489
|
+
const dbs = new DatabaseSchema();
|
|
490
|
+
dbs.defineDatasource({
|
|
491
491
|
name: 'memory',
|
|
492
492
|
adapter: 'memory',
|
|
493
493
|
});
|
|
494
|
-
|
|
494
|
+
dbs.defineModel({
|
|
495
495
|
name: 'model',
|
|
496
496
|
datasource: 'memory',
|
|
497
497
|
properties: {
|
|
@@ -505,7 +505,7 @@ describe('MemoryAdapter', function () {
|
|
|
505
505
|
},
|
|
506
506
|
},
|
|
507
507
|
});
|
|
508
|
-
const adapter = new MemoryAdapter(
|
|
508
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
509
509
|
const created = await adapter.create('model', {foo: undefined});
|
|
510
510
|
const idValue = created[DEF_PK];
|
|
511
511
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -516,12 +516,12 @@ describe('MemoryAdapter', function () {
|
|
|
516
516
|
});
|
|
517
517
|
|
|
518
518
|
it('sets default values for properties provided with a null value', async function () {
|
|
519
|
-
const
|
|
520
|
-
|
|
519
|
+
const dbs = new DatabaseSchema();
|
|
520
|
+
dbs.defineDatasource({
|
|
521
521
|
name: 'memory',
|
|
522
522
|
adapter: 'memory',
|
|
523
523
|
});
|
|
524
|
-
|
|
524
|
+
dbs.defineModel({
|
|
525
525
|
name: 'model',
|
|
526
526
|
datasource: 'memory',
|
|
527
527
|
properties: {
|
|
@@ -535,7 +535,7 @@ describe('MemoryAdapter', function () {
|
|
|
535
535
|
},
|
|
536
536
|
},
|
|
537
537
|
});
|
|
538
|
-
const adapter = new MemoryAdapter(
|
|
538
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
539
539
|
const created = await adapter.create('model', {foo: null});
|
|
540
540
|
const idValue = created[DEF_PK];
|
|
541
541
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -546,12 +546,12 @@ describe('MemoryAdapter', function () {
|
|
|
546
546
|
});
|
|
547
547
|
|
|
548
548
|
it('uses a specified column name for a primary key', async function () {
|
|
549
|
-
const
|
|
550
|
-
|
|
549
|
+
const dbs = new DatabaseSchema();
|
|
550
|
+
dbs.defineDatasource({
|
|
551
551
|
name: 'memory',
|
|
552
552
|
adapter: 'memory',
|
|
553
553
|
});
|
|
554
|
-
|
|
554
|
+
dbs.defineModel({
|
|
555
555
|
name: 'model',
|
|
556
556
|
datasource: 'memory',
|
|
557
557
|
properties: {
|
|
@@ -562,7 +562,7 @@ describe('MemoryAdapter', function () {
|
|
|
562
562
|
},
|
|
563
563
|
},
|
|
564
564
|
});
|
|
565
|
-
const adapter = new MemoryAdapter(
|
|
565
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
566
566
|
const created = await adapter.create('model', {});
|
|
567
567
|
expect(created).to.be.eql({foo: created.foo});
|
|
568
568
|
const table = adapter._getTableOrCreate('model');
|
|
@@ -571,12 +571,12 @@ describe('MemoryAdapter', function () {
|
|
|
571
571
|
});
|
|
572
572
|
|
|
573
573
|
it('uses a specified column name for a regular property', async function () {
|
|
574
|
-
const
|
|
575
|
-
|
|
574
|
+
const dbs = new DatabaseSchema();
|
|
575
|
+
dbs.defineDatasource({
|
|
576
576
|
name: 'memory',
|
|
577
577
|
adapter: 'memory',
|
|
578
578
|
});
|
|
579
|
-
|
|
579
|
+
dbs.defineModel({
|
|
580
580
|
name: 'model',
|
|
581
581
|
datasource: 'memory',
|
|
582
582
|
properties: {
|
|
@@ -586,7 +586,7 @@ describe('MemoryAdapter', function () {
|
|
|
586
586
|
},
|
|
587
587
|
},
|
|
588
588
|
});
|
|
589
|
-
const adapter = new MemoryAdapter(
|
|
589
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
590
590
|
const created = await adapter.create('model', {foo: 10});
|
|
591
591
|
const idValue = created[DEF_PK];
|
|
592
592
|
expect(created).to.be.eql({[DEF_PK]: idValue, foo: 10});
|
|
@@ -596,12 +596,12 @@ describe('MemoryAdapter', function () {
|
|
|
596
596
|
});
|
|
597
597
|
|
|
598
598
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
599
|
-
const
|
|
600
|
-
|
|
599
|
+
const dbs = new DatabaseSchema();
|
|
600
|
+
dbs.defineDatasource({
|
|
601
601
|
name: 'memory',
|
|
602
602
|
adapter: 'memory',
|
|
603
603
|
});
|
|
604
|
-
|
|
604
|
+
dbs.defineModel({
|
|
605
605
|
name: 'model',
|
|
606
606
|
datasource: 'memory',
|
|
607
607
|
properties: {
|
|
@@ -612,7 +612,7 @@ describe('MemoryAdapter', function () {
|
|
|
612
612
|
},
|
|
613
613
|
},
|
|
614
614
|
});
|
|
615
|
-
const adapter = new MemoryAdapter(
|
|
615
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
616
616
|
const created = await adapter.create('model', {});
|
|
617
617
|
const idValue = created[DEF_PK];
|
|
618
618
|
expect(created).to.be.eql({[DEF_PK]: idValue, foo: 10});
|
|
@@ -622,12 +622,12 @@ describe('MemoryAdapter', function () {
|
|
|
622
622
|
});
|
|
623
623
|
|
|
624
624
|
it('uses a short form of a fields clause to filter a return value', async function () {
|
|
625
|
-
const
|
|
626
|
-
|
|
625
|
+
const dbs = new DatabaseSchema();
|
|
626
|
+
dbs.defineDatasource({
|
|
627
627
|
name: 'memory',
|
|
628
628
|
adapter: 'memory',
|
|
629
629
|
});
|
|
630
|
-
|
|
630
|
+
dbs.defineModel({
|
|
631
631
|
name: 'model',
|
|
632
632
|
datasource: 'memory',
|
|
633
633
|
properties: {
|
|
@@ -635,7 +635,7 @@ describe('MemoryAdapter', function () {
|
|
|
635
635
|
bar: DataType.NUMBER,
|
|
636
636
|
},
|
|
637
637
|
});
|
|
638
|
-
const adapter = new MemoryAdapter(
|
|
638
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
639
639
|
const input = {foo: 'string', bar: 10};
|
|
640
640
|
const filter = {fields: 'foo'};
|
|
641
641
|
const result = await adapter.create('model', input, filter);
|
|
@@ -643,12 +643,12 @@ describe('MemoryAdapter', function () {
|
|
|
643
643
|
});
|
|
644
644
|
|
|
645
645
|
it('uses a full form of a fields clause to filter a return value', async function () {
|
|
646
|
-
const
|
|
647
|
-
|
|
646
|
+
const dbs = new DatabaseSchema();
|
|
647
|
+
dbs.defineDatasource({
|
|
648
648
|
name: 'memory',
|
|
649
649
|
adapter: 'memory',
|
|
650
650
|
});
|
|
651
|
-
|
|
651
|
+
dbs.defineModel({
|
|
652
652
|
name: 'model',
|
|
653
653
|
datasource: 'memory',
|
|
654
654
|
properties: {
|
|
@@ -657,7 +657,7 @@ describe('MemoryAdapter', function () {
|
|
|
657
657
|
baz: DataType.BOOLEAN,
|
|
658
658
|
},
|
|
659
659
|
});
|
|
660
|
-
const adapter = new MemoryAdapter(
|
|
660
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
661
661
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
662
662
|
const filter = {fields: ['foo', 'bar']};
|
|
663
663
|
const result = await adapter.create('model', input, filter);
|
|
@@ -669,12 +669,12 @@ describe('MemoryAdapter', function () {
|
|
|
669
669
|
});
|
|
670
670
|
|
|
671
671
|
it('a fields clause uses property names instead of column names', async function () {
|
|
672
|
-
const
|
|
673
|
-
|
|
672
|
+
const dbs = new DatabaseSchema();
|
|
673
|
+
dbs.defineDatasource({
|
|
674
674
|
name: 'memory',
|
|
675
675
|
adapter: 'memory',
|
|
676
676
|
});
|
|
677
|
-
|
|
677
|
+
dbs.defineModel({
|
|
678
678
|
name: 'model',
|
|
679
679
|
datasource: 'memory',
|
|
680
680
|
properties: {
|
|
@@ -692,7 +692,7 @@ describe('MemoryAdapter', function () {
|
|
|
692
692
|
},
|
|
693
693
|
},
|
|
694
694
|
});
|
|
695
|
-
const adapter = new MemoryAdapter(
|
|
695
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
696
696
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
697
697
|
const filter = {fields: ['foo', 'bar']};
|
|
698
698
|
const result = await adapter.create('model', input, filter);
|
|
@@ -706,12 +706,12 @@ describe('MemoryAdapter', function () {
|
|
|
706
706
|
|
|
707
707
|
describe('replaceById', function () {
|
|
708
708
|
it('removes properties when replacing an item by a given identifier', async function () {
|
|
709
|
-
const
|
|
710
|
-
|
|
709
|
+
const dbs = new DatabaseSchema();
|
|
710
|
+
dbs.defineDatasource({
|
|
711
711
|
name: 'memory',
|
|
712
712
|
adapter: 'memory',
|
|
713
713
|
});
|
|
714
|
-
|
|
714
|
+
dbs.defineModel({
|
|
715
715
|
name: 'model',
|
|
716
716
|
datasource: 'memory',
|
|
717
717
|
properties: {
|
|
@@ -719,7 +719,7 @@ describe('MemoryAdapter', function () {
|
|
|
719
719
|
bar: DataType.NUMBER,
|
|
720
720
|
},
|
|
721
721
|
});
|
|
722
|
-
const adapter = new MemoryAdapter(
|
|
722
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
723
723
|
const input = {foo: 1, bar: 2};
|
|
724
724
|
const created = await adapter.create('model', input);
|
|
725
725
|
const idValue = created[DEF_PK];
|
|
@@ -732,16 +732,16 @@ describe('MemoryAdapter', function () {
|
|
|
732
732
|
});
|
|
733
733
|
|
|
734
734
|
it('ignores identifier value in a given data in case of a default primary key', async function () {
|
|
735
|
-
const
|
|
736
|
-
|
|
735
|
+
const dbs = new DatabaseSchema();
|
|
736
|
+
dbs.defineDatasource({
|
|
737
737
|
name: 'memory',
|
|
738
738
|
adapter: 'memory',
|
|
739
739
|
});
|
|
740
|
-
|
|
740
|
+
dbs.defineModel({
|
|
741
741
|
name: 'model',
|
|
742
742
|
datasource: 'memory',
|
|
743
743
|
});
|
|
744
|
-
const adapter = new MemoryAdapter(
|
|
744
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
745
745
|
const createdModelData = await adapter.create('model', {[DEF_PK]: 10});
|
|
746
746
|
expect(createdModelData).to.be.eql({[DEF_PK]: 10});
|
|
747
747
|
const table = adapter._getTableOrCreate('model');
|
|
@@ -756,12 +756,12 @@ describe('MemoryAdapter', function () {
|
|
|
756
756
|
});
|
|
757
757
|
|
|
758
758
|
it('ignores identifier value in a given data in case of a specified primary key', async function () {
|
|
759
|
-
const
|
|
760
|
-
|
|
759
|
+
const dbs = new DatabaseSchema();
|
|
760
|
+
dbs.defineDatasource({
|
|
761
761
|
name: 'memory',
|
|
762
762
|
adapter: 'memory',
|
|
763
763
|
});
|
|
764
|
-
|
|
764
|
+
dbs.defineModel({
|
|
765
765
|
name: 'model',
|
|
766
766
|
datasource: 'memory',
|
|
767
767
|
properties: {
|
|
@@ -771,7 +771,7 @@ describe('MemoryAdapter', function () {
|
|
|
771
771
|
},
|
|
772
772
|
},
|
|
773
773
|
});
|
|
774
|
-
const adapter = new MemoryAdapter(
|
|
774
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
775
775
|
const createdModelData = await adapter.create('model', {myId: 10});
|
|
776
776
|
expect(createdModelData).to.be.eql({myId: 10});
|
|
777
777
|
const table = adapter._getTableOrCreate('model');
|
|
@@ -786,12 +786,12 @@ describe('MemoryAdapter', function () {
|
|
|
786
786
|
});
|
|
787
787
|
|
|
788
788
|
it('sets a default values for removed properties when replacing an item', async function () {
|
|
789
|
-
const
|
|
790
|
-
|
|
789
|
+
const dbs = new DatabaseSchema();
|
|
790
|
+
dbs.defineDatasource({
|
|
791
791
|
name: 'memory',
|
|
792
792
|
adapter: 'memory',
|
|
793
793
|
});
|
|
794
|
-
|
|
794
|
+
dbs.defineModel({
|
|
795
795
|
name: 'model',
|
|
796
796
|
datasource: 'memory',
|
|
797
797
|
properties: {
|
|
@@ -805,7 +805,7 @@ describe('MemoryAdapter', function () {
|
|
|
805
805
|
},
|
|
806
806
|
},
|
|
807
807
|
});
|
|
808
|
-
const adapter = new MemoryAdapter(
|
|
808
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
809
809
|
const created = await adapter.create('model', {});
|
|
810
810
|
const idValue = created[DEF_PK];
|
|
811
811
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -827,12 +827,12 @@ describe('MemoryAdapter', function () {
|
|
|
827
827
|
});
|
|
828
828
|
|
|
829
829
|
it('sets a default values for replaced properties with an undefined value', async function () {
|
|
830
|
-
const
|
|
831
|
-
|
|
830
|
+
const dbs = new DatabaseSchema();
|
|
831
|
+
dbs.defineDatasource({
|
|
832
832
|
name: 'memory',
|
|
833
833
|
adapter: 'memory',
|
|
834
834
|
});
|
|
835
|
-
|
|
835
|
+
dbs.defineModel({
|
|
836
836
|
name: 'model',
|
|
837
837
|
datasource: 'memory',
|
|
838
838
|
properties: {
|
|
@@ -846,7 +846,7 @@ describe('MemoryAdapter', function () {
|
|
|
846
846
|
},
|
|
847
847
|
},
|
|
848
848
|
});
|
|
849
|
-
const adapter = new MemoryAdapter(
|
|
849
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
850
850
|
const created = await adapter.create('model', {});
|
|
851
851
|
const idValue = created[DEF_PK];
|
|
852
852
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -861,12 +861,12 @@ describe('MemoryAdapter', function () {
|
|
|
861
861
|
});
|
|
862
862
|
|
|
863
863
|
it('sets a default values for replaced properties with a null value', async function () {
|
|
864
|
-
const
|
|
865
|
-
|
|
864
|
+
const dbs = new DatabaseSchema();
|
|
865
|
+
dbs.defineDatasource({
|
|
866
866
|
name: 'memory',
|
|
867
867
|
adapter: 'memory',
|
|
868
868
|
});
|
|
869
|
-
|
|
869
|
+
dbs.defineModel({
|
|
870
870
|
name: 'model',
|
|
871
871
|
datasource: 'memory',
|
|
872
872
|
properties: {
|
|
@@ -880,7 +880,7 @@ describe('MemoryAdapter', function () {
|
|
|
880
880
|
},
|
|
881
881
|
},
|
|
882
882
|
});
|
|
883
|
-
const adapter = new MemoryAdapter(
|
|
883
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
884
884
|
const created = await adapter.create('model', {});
|
|
885
885
|
const idValue = created[DEF_PK];
|
|
886
886
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -895,12 +895,12 @@ describe('MemoryAdapter', function () {
|
|
|
895
895
|
});
|
|
896
896
|
|
|
897
897
|
it('throws an error if a given identifier does not exist', async function () {
|
|
898
|
-
const
|
|
899
|
-
|
|
898
|
+
const dbs = new DatabaseSchema();
|
|
899
|
+
dbs.defineDatasource({
|
|
900
900
|
name: 'memory',
|
|
901
901
|
adapter: 'memory',
|
|
902
902
|
});
|
|
903
|
-
|
|
903
|
+
dbs.defineModel({
|
|
904
904
|
name: 'model',
|
|
905
905
|
datasource: 'memory',
|
|
906
906
|
properties: {
|
|
@@ -908,7 +908,7 @@ describe('MemoryAdapter', function () {
|
|
|
908
908
|
bar: DataType.NUMBER,
|
|
909
909
|
},
|
|
910
910
|
});
|
|
911
|
-
const adapter = new MemoryAdapter(
|
|
911
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
912
912
|
const promise = adapter.replaceById('model', 1, {foo: 2});
|
|
913
913
|
await expect(promise).to.be.rejectedWith(
|
|
914
914
|
format(
|
|
@@ -919,12 +919,12 @@ describe('MemoryAdapter', function () {
|
|
|
919
919
|
});
|
|
920
920
|
|
|
921
921
|
it('uses a specified column name for a primary key', async function () {
|
|
922
|
-
const
|
|
923
|
-
|
|
922
|
+
const dbs = new DatabaseSchema();
|
|
923
|
+
dbs.defineDatasource({
|
|
924
924
|
name: 'memory',
|
|
925
925
|
adapter: 'memory',
|
|
926
926
|
});
|
|
927
|
-
|
|
927
|
+
dbs.defineModel({
|
|
928
928
|
name: 'model',
|
|
929
929
|
datasource: 'memory',
|
|
930
930
|
properties: {
|
|
@@ -937,7 +937,7 @@ describe('MemoryAdapter', function () {
|
|
|
937
937
|
baz: DataType.NUMBER,
|
|
938
938
|
},
|
|
939
939
|
});
|
|
940
|
-
const adapter = new MemoryAdapter(
|
|
940
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
941
941
|
const input = {bar: 1, baz: 2};
|
|
942
942
|
const createdModelData = await adapter.create('model', input);
|
|
943
943
|
expect(createdModelData).to.be.eql({
|
|
@@ -968,12 +968,12 @@ describe('MemoryAdapter', function () {
|
|
|
968
968
|
});
|
|
969
969
|
|
|
970
970
|
it('uses a specified column name for a regular property', async function () {
|
|
971
|
-
const
|
|
972
|
-
|
|
971
|
+
const dbs = new DatabaseSchema();
|
|
972
|
+
dbs.defineDatasource({
|
|
973
973
|
name: 'memory',
|
|
974
974
|
adapter: 'memory',
|
|
975
975
|
});
|
|
976
|
-
|
|
976
|
+
dbs.defineModel({
|
|
977
977
|
name: 'model',
|
|
978
978
|
datasource: 'memory',
|
|
979
979
|
properties: {
|
|
@@ -984,7 +984,7 @@ describe('MemoryAdapter', function () {
|
|
|
984
984
|
bar: DataType.NUMBER,
|
|
985
985
|
},
|
|
986
986
|
});
|
|
987
|
-
const adapter = new MemoryAdapter(
|
|
987
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
988
988
|
const input = {foo: 1, bar: 2};
|
|
989
989
|
const createdModelData = await adapter.create('model', input);
|
|
990
990
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -1011,12 +1011,12 @@ describe('MemoryAdapter', function () {
|
|
|
1011
1011
|
});
|
|
1012
1012
|
|
|
1013
1013
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1014
|
+
const dbs = new DatabaseSchema();
|
|
1015
|
+
dbs.defineDatasource({
|
|
1016
1016
|
name: 'memory',
|
|
1017
1017
|
adapter: 'memory',
|
|
1018
1018
|
});
|
|
1019
|
-
|
|
1019
|
+
dbs.defineModel({
|
|
1020
1020
|
name: 'model',
|
|
1021
1021
|
datasource: 'memory',
|
|
1022
1022
|
properties: {
|
|
@@ -1031,7 +1031,7 @@ describe('MemoryAdapter', function () {
|
|
|
1031
1031
|
},
|
|
1032
1032
|
},
|
|
1033
1033
|
});
|
|
1034
|
-
const adapter = new MemoryAdapter(
|
|
1034
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1035
1035
|
const createdModelData = await adapter.create('model', {});
|
|
1036
1036
|
const idValue = createdModelData[DEF_PK];
|
|
1037
1037
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1063,12 +1063,12 @@ describe('MemoryAdapter', function () {
|
|
|
1063
1063
|
});
|
|
1064
1064
|
|
|
1065
1065
|
it('allows to specify a short form of a fields clause to filter a return value', async function () {
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1066
|
+
const dbs = new DatabaseSchema();
|
|
1067
|
+
dbs.defineDatasource({
|
|
1068
1068
|
name: 'memory',
|
|
1069
1069
|
adapter: 'memory',
|
|
1070
1070
|
});
|
|
1071
|
-
|
|
1071
|
+
dbs.defineModel({
|
|
1072
1072
|
name: 'model',
|
|
1073
1073
|
datasource: 'memory',
|
|
1074
1074
|
properties: {
|
|
@@ -1076,7 +1076,7 @@ describe('MemoryAdapter', function () {
|
|
|
1076
1076
|
bar: DataType.NUMBER,
|
|
1077
1077
|
},
|
|
1078
1078
|
});
|
|
1079
|
-
const adapter = new MemoryAdapter(
|
|
1079
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1080
1080
|
const input = {foo: 'string', bar: 10};
|
|
1081
1081
|
const createdModelData = await adapter.create('model', input);
|
|
1082
1082
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -1096,12 +1096,12 @@ describe('MemoryAdapter', function () {
|
|
|
1096
1096
|
});
|
|
1097
1097
|
|
|
1098
1098
|
it('allows to specify a full form of a fields clause to filter a return value', async function () {
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1099
|
+
const dbs = new DatabaseSchema();
|
|
1100
|
+
dbs.defineDatasource({
|
|
1101
1101
|
name: 'memory',
|
|
1102
1102
|
adapter: 'memory',
|
|
1103
1103
|
});
|
|
1104
|
-
|
|
1104
|
+
dbs.defineModel({
|
|
1105
1105
|
name: 'model',
|
|
1106
1106
|
datasource: 'memory',
|
|
1107
1107
|
properties: {
|
|
@@ -1110,7 +1110,7 @@ describe('MemoryAdapter', function () {
|
|
|
1110
1110
|
baz: DataType.BOOLEAN,
|
|
1111
1111
|
},
|
|
1112
1112
|
});
|
|
1113
|
-
const adapter = new MemoryAdapter(
|
|
1113
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1114
1114
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
1115
1115
|
const createdModelData = await adapter.create('model', input);
|
|
1116
1116
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -1134,12 +1134,12 @@ describe('MemoryAdapter', function () {
|
|
|
1134
1134
|
});
|
|
1135
1135
|
|
|
1136
1136
|
it('a fields clause uses property names instead of column names', async function () {
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1137
|
+
const dbs = new DatabaseSchema();
|
|
1138
|
+
dbs.defineDatasource({
|
|
1139
1139
|
name: 'memory',
|
|
1140
1140
|
adapter: 'memory',
|
|
1141
1141
|
});
|
|
1142
|
-
|
|
1142
|
+
dbs.defineModel({
|
|
1143
1143
|
name: 'model',
|
|
1144
1144
|
datasource: 'memory',
|
|
1145
1145
|
properties: {
|
|
@@ -1157,7 +1157,7 @@ describe('MemoryAdapter', function () {
|
|
|
1157
1157
|
},
|
|
1158
1158
|
},
|
|
1159
1159
|
});
|
|
1160
|
-
const adapter = new MemoryAdapter(
|
|
1160
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1161
1161
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
1162
1162
|
const createdModelData = await adapter.create('model', input);
|
|
1163
1163
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -1193,12 +1193,12 @@ describe('MemoryAdapter', function () {
|
|
|
1193
1193
|
|
|
1194
1194
|
describe('replaceOrCreate', function () {
|
|
1195
1195
|
it('generates a new identifier when a value of a primary key has not provided', async function () {
|
|
1196
|
-
const
|
|
1197
|
-
|
|
1196
|
+
const dbs = new DatabaseSchema();
|
|
1197
|
+
dbs.defineDatasource({
|
|
1198
1198
|
name: 'memory',
|
|
1199
1199
|
adapter: 'memory',
|
|
1200
1200
|
});
|
|
1201
|
-
|
|
1201
|
+
dbs.defineModel({
|
|
1202
1202
|
name: 'model',
|
|
1203
1203
|
datasource: 'memory',
|
|
1204
1204
|
properties: {
|
|
@@ -1206,7 +1206,7 @@ describe('MemoryAdapter', function () {
|
|
|
1206
1206
|
bar: DataType.NUMBER,
|
|
1207
1207
|
},
|
|
1208
1208
|
});
|
|
1209
|
-
const adapter = new MemoryAdapter(
|
|
1209
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1210
1210
|
const input = {foo: 'string', bar: 10};
|
|
1211
1211
|
const created = await adapter.replaceOrCreate('model', input);
|
|
1212
1212
|
const idValue = created[DEF_PK];
|
|
@@ -1217,12 +1217,12 @@ describe('MemoryAdapter', function () {
|
|
|
1217
1217
|
});
|
|
1218
1218
|
|
|
1219
1219
|
it('generates a new identifier when a value of a primary key is undefined', async function () {
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1220
|
+
const dbs = new DatabaseSchema();
|
|
1221
|
+
dbs.defineDatasource({
|
|
1222
1222
|
name: 'memory',
|
|
1223
1223
|
adapter: 'memory',
|
|
1224
1224
|
});
|
|
1225
|
-
|
|
1225
|
+
dbs.defineModel({
|
|
1226
1226
|
name: 'model',
|
|
1227
1227
|
datasource: 'memory',
|
|
1228
1228
|
properties: {
|
|
@@ -1230,7 +1230,7 @@ describe('MemoryAdapter', function () {
|
|
|
1230
1230
|
bar: DataType.NUMBER,
|
|
1231
1231
|
},
|
|
1232
1232
|
});
|
|
1233
|
-
const adapter = new MemoryAdapter(
|
|
1233
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1234
1234
|
const input = {
|
|
1235
1235
|
[DEF_PK]: undefined,
|
|
1236
1236
|
foo: 'string',
|
|
@@ -1245,12 +1245,12 @@ describe('MemoryAdapter', function () {
|
|
|
1245
1245
|
});
|
|
1246
1246
|
|
|
1247
1247
|
it('generates a new identifier when a value of a primary key is null', async function () {
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1248
|
+
const dbs = new DatabaseSchema();
|
|
1249
|
+
dbs.defineDatasource({
|
|
1250
1250
|
name: 'memory',
|
|
1251
1251
|
adapter: 'memory',
|
|
1252
1252
|
});
|
|
1253
|
-
|
|
1253
|
+
dbs.defineModel({
|
|
1254
1254
|
name: 'model',
|
|
1255
1255
|
datasource: 'memory',
|
|
1256
1256
|
properties: {
|
|
@@ -1258,7 +1258,7 @@ describe('MemoryAdapter', function () {
|
|
|
1258
1258
|
bar: DataType.NUMBER,
|
|
1259
1259
|
},
|
|
1260
1260
|
});
|
|
1261
|
-
const adapter = new MemoryAdapter(
|
|
1261
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1262
1262
|
const input = {
|
|
1263
1263
|
[DEF_PK]: null,
|
|
1264
1264
|
foo: 'string',
|
|
@@ -1273,12 +1273,12 @@ describe('MemoryAdapter', function () {
|
|
|
1273
1273
|
});
|
|
1274
1274
|
|
|
1275
1275
|
it('generates a new identifier when a value of a primary key is an empty string', async function () {
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1276
|
+
const dbs = new DatabaseSchema();
|
|
1277
|
+
dbs.defineDatasource({
|
|
1278
1278
|
name: 'memory',
|
|
1279
1279
|
adapter: 'memory',
|
|
1280
1280
|
});
|
|
1281
|
-
|
|
1281
|
+
dbs.defineModel({
|
|
1282
1282
|
name: 'model',
|
|
1283
1283
|
datasource: 'memory',
|
|
1284
1284
|
properties: {
|
|
@@ -1286,7 +1286,7 @@ describe('MemoryAdapter', function () {
|
|
|
1286
1286
|
bar: DataType.NUMBER,
|
|
1287
1287
|
},
|
|
1288
1288
|
});
|
|
1289
|
-
const adapter = new MemoryAdapter(
|
|
1289
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1290
1290
|
const input = {
|
|
1291
1291
|
[DEF_PK]: '',
|
|
1292
1292
|
foo: 'string',
|
|
@@ -1302,12 +1302,12 @@ describe('MemoryAdapter', function () {
|
|
|
1302
1302
|
});
|
|
1303
1303
|
|
|
1304
1304
|
it('generates a new identifier when a value of a primary key is zero', async function () {
|
|
1305
|
-
const
|
|
1306
|
-
|
|
1305
|
+
const dbs = new DatabaseSchema();
|
|
1306
|
+
dbs.defineDatasource({
|
|
1307
1307
|
name: 'memory',
|
|
1308
1308
|
adapter: 'memory',
|
|
1309
1309
|
});
|
|
1310
|
-
|
|
1310
|
+
dbs.defineModel({
|
|
1311
1311
|
name: 'model',
|
|
1312
1312
|
datasource: 'memory',
|
|
1313
1313
|
properties: {
|
|
@@ -1315,7 +1315,7 @@ describe('MemoryAdapter', function () {
|
|
|
1315
1315
|
bar: DataType.NUMBER,
|
|
1316
1316
|
},
|
|
1317
1317
|
});
|
|
1318
|
-
const adapter = new MemoryAdapter(
|
|
1318
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1319
1319
|
const input = {
|
|
1320
1320
|
[DEF_PK]: 0,
|
|
1321
1321
|
foo: 'string',
|
|
@@ -1331,12 +1331,12 @@ describe('MemoryAdapter', function () {
|
|
|
1331
1331
|
});
|
|
1332
1332
|
|
|
1333
1333
|
it('generates a new identifier for a primary key of a "number" type', async function () {
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1334
|
+
const dbs = new DatabaseSchema();
|
|
1335
|
+
dbs.defineDatasource({
|
|
1336
1336
|
name: 'memory',
|
|
1337
1337
|
adapter: 'memory',
|
|
1338
1338
|
});
|
|
1339
|
-
|
|
1339
|
+
dbs.defineModel({
|
|
1340
1340
|
name: 'model',
|
|
1341
1341
|
datasource: 'memory',
|
|
1342
1342
|
properties: {
|
|
@@ -1346,7 +1346,7 @@ describe('MemoryAdapter', function () {
|
|
|
1346
1346
|
},
|
|
1347
1347
|
},
|
|
1348
1348
|
});
|
|
1349
|
-
const adapter = new MemoryAdapter(
|
|
1349
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1350
1350
|
const result1 = await adapter.replaceOrCreate('model', {});
|
|
1351
1351
|
const result2 = await adapter.replaceOrCreate('model', {});
|
|
1352
1352
|
const result3 = await adapter.replaceOrCreate('model', {});
|
|
@@ -1356,12 +1356,12 @@ describe('MemoryAdapter', function () {
|
|
|
1356
1356
|
});
|
|
1357
1357
|
|
|
1358
1358
|
it('generates a new identifier for a primary key of an "any" type', async function () {
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1359
|
+
const dbs = new DatabaseSchema();
|
|
1360
|
+
dbs.defineDatasource({
|
|
1361
1361
|
name: 'memory',
|
|
1362
1362
|
adapter: 'memory',
|
|
1363
1363
|
});
|
|
1364
|
-
|
|
1364
|
+
dbs.defineModel({
|
|
1365
1365
|
name: 'model',
|
|
1366
1366
|
datasource: 'memory',
|
|
1367
1367
|
properties: {
|
|
@@ -1371,7 +1371,7 @@ describe('MemoryAdapter', function () {
|
|
|
1371
1371
|
},
|
|
1372
1372
|
},
|
|
1373
1373
|
});
|
|
1374
|
-
const adapter = new MemoryAdapter(
|
|
1374
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1375
1375
|
const result1 = await adapter.replaceOrCreate('model', {});
|
|
1376
1376
|
const result2 = await adapter.replaceOrCreate('model', {});
|
|
1377
1377
|
const result3 = await adapter.replaceOrCreate('model', {});
|
|
@@ -1381,12 +1381,12 @@ describe('MemoryAdapter', function () {
|
|
|
1381
1381
|
});
|
|
1382
1382
|
|
|
1383
1383
|
it('throws an error when generating a new value for a primary key of a "string" type', async function () {
|
|
1384
|
-
const
|
|
1385
|
-
|
|
1384
|
+
const dbs = new DatabaseSchema();
|
|
1385
|
+
dbs.defineDatasource({
|
|
1386
1386
|
name: 'memory',
|
|
1387
1387
|
adapter: 'memory',
|
|
1388
1388
|
});
|
|
1389
|
-
|
|
1389
|
+
dbs.defineModel({
|
|
1390
1390
|
name: 'model',
|
|
1391
1391
|
datasource: 'memory',
|
|
1392
1392
|
properties: {
|
|
@@ -1396,7 +1396,7 @@ describe('MemoryAdapter', function () {
|
|
|
1396
1396
|
},
|
|
1397
1397
|
},
|
|
1398
1398
|
});
|
|
1399
|
-
const adapter = new MemoryAdapter(
|
|
1399
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1400
1400
|
const promise = adapter.replaceOrCreate('model', {
|
|
1401
1401
|
foo: 'string',
|
|
1402
1402
|
bar: 10,
|
|
@@ -1411,12 +1411,12 @@ describe('MemoryAdapter', function () {
|
|
|
1411
1411
|
});
|
|
1412
1412
|
|
|
1413
1413
|
it('throws an error when generating a new value for a primary key of a "boolean" type', async function () {
|
|
1414
|
-
const
|
|
1415
|
-
|
|
1414
|
+
const dbs = new DatabaseSchema();
|
|
1415
|
+
dbs.defineDatasource({
|
|
1416
1416
|
name: 'memory',
|
|
1417
1417
|
adapter: 'memory',
|
|
1418
1418
|
});
|
|
1419
|
-
|
|
1419
|
+
dbs.defineModel({
|
|
1420
1420
|
name: 'model',
|
|
1421
1421
|
datasource: 'memory',
|
|
1422
1422
|
properties: {
|
|
@@ -1426,7 +1426,7 @@ describe('MemoryAdapter', function () {
|
|
|
1426
1426
|
},
|
|
1427
1427
|
},
|
|
1428
1428
|
});
|
|
1429
|
-
const adapter = new MemoryAdapter(
|
|
1429
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1430
1430
|
const promise = adapter.replaceOrCreate('model', {
|
|
1431
1431
|
foo: 'string',
|
|
1432
1432
|
bar: 10,
|
|
@@ -1441,12 +1441,12 @@ describe('MemoryAdapter', function () {
|
|
|
1441
1441
|
});
|
|
1442
1442
|
|
|
1443
1443
|
it('throws an error when generating a new value for a primary key of an "array" type', async function () {
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1444
|
+
const dbs = new DatabaseSchema();
|
|
1445
|
+
dbs.defineDatasource({
|
|
1446
1446
|
name: 'memory',
|
|
1447
1447
|
adapter: 'memory',
|
|
1448
1448
|
});
|
|
1449
|
-
|
|
1449
|
+
dbs.defineModel({
|
|
1450
1450
|
name: 'model',
|
|
1451
1451
|
datasource: 'memory',
|
|
1452
1452
|
properties: {
|
|
@@ -1457,7 +1457,7 @@ describe('MemoryAdapter', function () {
|
|
|
1457
1457
|
},
|
|
1458
1458
|
},
|
|
1459
1459
|
});
|
|
1460
|
-
const adapter = new MemoryAdapter(
|
|
1460
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1461
1461
|
const promise = adapter.replaceOrCreate('model', {});
|
|
1462
1462
|
await expect(promise).to.be.rejectedWith(
|
|
1463
1463
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -1469,12 +1469,12 @@ describe('MemoryAdapter', function () {
|
|
|
1469
1469
|
});
|
|
1470
1470
|
|
|
1471
1471
|
it('throws an error when generating a new value for a primary key of an "object" type', async function () {
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1472
|
+
const dbs = new DatabaseSchema();
|
|
1473
|
+
dbs.defineDatasource({
|
|
1474
1474
|
name: 'memory',
|
|
1475
1475
|
adapter: 'memory',
|
|
1476
1476
|
});
|
|
1477
|
-
|
|
1477
|
+
dbs.defineModel({
|
|
1478
1478
|
name: 'model',
|
|
1479
1479
|
datasource: 'memory',
|
|
1480
1480
|
properties: {
|
|
@@ -1484,7 +1484,7 @@ describe('MemoryAdapter', function () {
|
|
|
1484
1484
|
},
|
|
1485
1485
|
},
|
|
1486
1486
|
});
|
|
1487
|
-
const adapter = new MemoryAdapter(
|
|
1487
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1488
1488
|
const promise = adapter.replaceOrCreate('model', {});
|
|
1489
1489
|
await expect(promise).to.be.rejectedWith(
|
|
1490
1490
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
@@ -1496,12 +1496,12 @@ describe('MemoryAdapter', function () {
|
|
|
1496
1496
|
});
|
|
1497
1497
|
|
|
1498
1498
|
it('allows to specify an identifier value for a new item', async function () {
|
|
1499
|
-
const
|
|
1500
|
-
|
|
1499
|
+
const dbs = new DatabaseSchema();
|
|
1500
|
+
dbs.defineDatasource({
|
|
1501
1501
|
name: 'memory',
|
|
1502
1502
|
adapter: 'memory',
|
|
1503
1503
|
});
|
|
1504
|
-
|
|
1504
|
+
dbs.defineModel({
|
|
1505
1505
|
name: 'model',
|
|
1506
1506
|
datasource: 'memory',
|
|
1507
1507
|
properties: {
|
|
@@ -1509,7 +1509,7 @@ describe('MemoryAdapter', function () {
|
|
|
1509
1509
|
bar: DataType.NUMBER,
|
|
1510
1510
|
},
|
|
1511
1511
|
});
|
|
1512
|
-
const adapter = new MemoryAdapter(
|
|
1512
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1513
1513
|
const idValue = 5;
|
|
1514
1514
|
const input = {foo: 'string', bar: 10};
|
|
1515
1515
|
const created = await adapter.replaceOrCreate('model', {
|
|
@@ -1523,12 +1523,12 @@ describe('MemoryAdapter', function () {
|
|
|
1523
1523
|
});
|
|
1524
1524
|
|
|
1525
1525
|
it('sets default values if they are not provided for a new item', async function () {
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1526
|
+
const dbs = new DatabaseSchema();
|
|
1527
|
+
dbs.defineDatasource({
|
|
1528
1528
|
name: 'memory',
|
|
1529
1529
|
adapter: 'memory',
|
|
1530
1530
|
});
|
|
1531
|
-
|
|
1531
|
+
dbs.defineModel({
|
|
1532
1532
|
name: 'model',
|
|
1533
1533
|
datasource: 'memory',
|
|
1534
1534
|
properties: {
|
|
@@ -1542,7 +1542,7 @@ describe('MemoryAdapter', function () {
|
|
|
1542
1542
|
},
|
|
1543
1543
|
},
|
|
1544
1544
|
});
|
|
1545
|
-
const adapter = new MemoryAdapter(
|
|
1545
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1546
1546
|
const created = await adapter.replaceOrCreate('model', {});
|
|
1547
1547
|
const idValue = created[DEF_PK];
|
|
1548
1548
|
const defaults = {foo: 10, bar: 'string'};
|
|
@@ -1553,12 +1553,12 @@ describe('MemoryAdapter', function () {
|
|
|
1553
1553
|
});
|
|
1554
1554
|
|
|
1555
1555
|
it('sets default values for properties provided with an undefined value', async function () {
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1556
|
+
const dbs = new DatabaseSchema();
|
|
1557
|
+
dbs.defineDatasource({
|
|
1558
1558
|
name: 'memory',
|
|
1559
1559
|
adapter: 'memory',
|
|
1560
1560
|
});
|
|
1561
|
-
|
|
1561
|
+
dbs.defineModel({
|
|
1562
1562
|
name: 'model',
|
|
1563
1563
|
datasource: 'memory',
|
|
1564
1564
|
properties: {
|
|
@@ -1572,7 +1572,7 @@ describe('MemoryAdapter', function () {
|
|
|
1572
1572
|
},
|
|
1573
1573
|
},
|
|
1574
1574
|
});
|
|
1575
|
-
const adapter = new MemoryAdapter(
|
|
1575
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1576
1576
|
const created = await adapter.replaceOrCreate('model', {foo: undefined});
|
|
1577
1577
|
const idValue = created[DEF_PK];
|
|
1578
1578
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1583,12 +1583,12 @@ describe('MemoryAdapter', function () {
|
|
|
1583
1583
|
});
|
|
1584
1584
|
|
|
1585
1585
|
it('sets default values for properties provided with a null value', async function () {
|
|
1586
|
-
const
|
|
1587
|
-
|
|
1586
|
+
const dbs = new DatabaseSchema();
|
|
1587
|
+
dbs.defineDatasource({
|
|
1588
1588
|
name: 'memory',
|
|
1589
1589
|
adapter: 'memory',
|
|
1590
1590
|
});
|
|
1591
|
-
|
|
1591
|
+
dbs.defineModel({
|
|
1592
1592
|
name: 'model',
|
|
1593
1593
|
datasource: 'memory',
|
|
1594
1594
|
properties: {
|
|
@@ -1602,7 +1602,7 @@ describe('MemoryAdapter', function () {
|
|
|
1602
1602
|
},
|
|
1603
1603
|
},
|
|
1604
1604
|
});
|
|
1605
|
-
const adapter = new MemoryAdapter(
|
|
1605
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1606
1606
|
const created = await adapter.replaceOrCreate('model', {foo: null});
|
|
1607
1607
|
const idValue = created[DEF_PK];
|
|
1608
1608
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1613,12 +1613,12 @@ describe('MemoryAdapter', function () {
|
|
|
1613
1613
|
});
|
|
1614
1614
|
|
|
1615
1615
|
it('uses a specified column name for a primary key', async function () {
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1616
|
+
const dbs = new DatabaseSchema();
|
|
1617
|
+
dbs.defineDatasource({
|
|
1618
1618
|
name: 'memory',
|
|
1619
1619
|
adapter: 'memory',
|
|
1620
1620
|
});
|
|
1621
|
-
|
|
1621
|
+
dbs.defineModel({
|
|
1622
1622
|
name: 'model',
|
|
1623
1623
|
datasource: 'memory',
|
|
1624
1624
|
properties: {
|
|
@@ -1629,7 +1629,7 @@ describe('MemoryAdapter', function () {
|
|
|
1629
1629
|
},
|
|
1630
1630
|
},
|
|
1631
1631
|
});
|
|
1632
|
-
const adapter = new MemoryAdapter(
|
|
1632
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1633
1633
|
const created = await adapter.replaceOrCreate('model', {});
|
|
1634
1634
|
expect(created).to.be.eql({foo: created.foo});
|
|
1635
1635
|
const table = adapter._getTableOrCreate('model');
|
|
@@ -1638,12 +1638,12 @@ describe('MemoryAdapter', function () {
|
|
|
1638
1638
|
});
|
|
1639
1639
|
|
|
1640
1640
|
it('uses a specified column name for a regular property', async function () {
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1641
|
+
const dbs = new DatabaseSchema();
|
|
1642
|
+
dbs.defineDatasource({
|
|
1643
1643
|
name: 'memory',
|
|
1644
1644
|
adapter: 'memory',
|
|
1645
1645
|
});
|
|
1646
|
-
|
|
1646
|
+
dbs.defineModel({
|
|
1647
1647
|
name: 'model',
|
|
1648
1648
|
datasource: 'memory',
|
|
1649
1649
|
properties: {
|
|
@@ -1653,7 +1653,7 @@ describe('MemoryAdapter', function () {
|
|
|
1653
1653
|
},
|
|
1654
1654
|
},
|
|
1655
1655
|
});
|
|
1656
|
-
const adapter = new MemoryAdapter(
|
|
1656
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1657
1657
|
const created = await adapter.replaceOrCreate('model', {foo: 10});
|
|
1658
1658
|
const idValue = created[DEF_PK];
|
|
1659
1659
|
expect(created).to.be.eql({[DEF_PK]: idValue, foo: 10});
|
|
@@ -1663,12 +1663,12 @@ describe('MemoryAdapter', function () {
|
|
|
1663
1663
|
});
|
|
1664
1664
|
|
|
1665
1665
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
1666
|
-
const
|
|
1667
|
-
|
|
1666
|
+
const dbs = new DatabaseSchema();
|
|
1667
|
+
dbs.defineDatasource({
|
|
1668
1668
|
name: 'memory',
|
|
1669
1669
|
adapter: 'memory',
|
|
1670
1670
|
});
|
|
1671
|
-
|
|
1671
|
+
dbs.defineModel({
|
|
1672
1672
|
name: 'model',
|
|
1673
1673
|
datasource: 'memory',
|
|
1674
1674
|
properties: {
|
|
@@ -1679,7 +1679,7 @@ describe('MemoryAdapter', function () {
|
|
|
1679
1679
|
},
|
|
1680
1680
|
},
|
|
1681
1681
|
});
|
|
1682
|
-
const adapter = new MemoryAdapter(
|
|
1682
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1683
1683
|
const created = await adapter.replaceOrCreate('model', {});
|
|
1684
1684
|
const idValue = created[DEF_PK];
|
|
1685
1685
|
expect(created).to.be.eql({[DEF_PK]: idValue, foo: 10});
|
|
@@ -1689,12 +1689,12 @@ describe('MemoryAdapter', function () {
|
|
|
1689
1689
|
});
|
|
1690
1690
|
|
|
1691
1691
|
it('uses a short form of a fields clause to filter a return value', async function () {
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1692
|
+
const dbs = new DatabaseSchema();
|
|
1693
|
+
dbs.defineDatasource({
|
|
1694
1694
|
name: 'memory',
|
|
1695
1695
|
adapter: 'memory',
|
|
1696
1696
|
});
|
|
1697
|
-
|
|
1697
|
+
dbs.defineModel({
|
|
1698
1698
|
name: 'model',
|
|
1699
1699
|
datasource: 'memory',
|
|
1700
1700
|
properties: {
|
|
@@ -1702,7 +1702,7 @@ describe('MemoryAdapter', function () {
|
|
|
1702
1702
|
bar: DataType.NUMBER,
|
|
1703
1703
|
},
|
|
1704
1704
|
});
|
|
1705
|
-
const adapter = new MemoryAdapter(
|
|
1705
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1706
1706
|
const input = {foo: 'string', bar: 10};
|
|
1707
1707
|
const filter = {fields: 'foo'};
|
|
1708
1708
|
const result = await adapter.replaceOrCreate('model', input, filter);
|
|
@@ -1710,12 +1710,12 @@ describe('MemoryAdapter', function () {
|
|
|
1710
1710
|
});
|
|
1711
1711
|
|
|
1712
1712
|
it('uses a full form of a fields clause to filter a return value', async function () {
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1713
|
+
const dbs = new DatabaseSchema();
|
|
1714
|
+
dbs.defineDatasource({
|
|
1715
1715
|
name: 'memory',
|
|
1716
1716
|
adapter: 'memory',
|
|
1717
1717
|
});
|
|
1718
|
-
|
|
1718
|
+
dbs.defineModel({
|
|
1719
1719
|
name: 'model',
|
|
1720
1720
|
datasource: 'memory',
|
|
1721
1721
|
properties: {
|
|
@@ -1724,7 +1724,7 @@ describe('MemoryAdapter', function () {
|
|
|
1724
1724
|
baz: DataType.BOOLEAN,
|
|
1725
1725
|
},
|
|
1726
1726
|
});
|
|
1727
|
-
const adapter = new MemoryAdapter(
|
|
1727
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1728
1728
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
1729
1729
|
const filter = {fields: ['foo', 'bar']};
|
|
1730
1730
|
const result = await adapter.replaceOrCreate('model', input, filter);
|
|
@@ -1736,12 +1736,12 @@ describe('MemoryAdapter', function () {
|
|
|
1736
1736
|
});
|
|
1737
1737
|
|
|
1738
1738
|
it('a fields clause uses property names instead of column names', async function () {
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1739
|
+
const dbs = new DatabaseSchema();
|
|
1740
|
+
dbs.defineDatasource({
|
|
1741
1741
|
name: 'memory',
|
|
1742
1742
|
adapter: 'memory',
|
|
1743
1743
|
});
|
|
1744
|
-
|
|
1744
|
+
dbs.defineModel({
|
|
1745
1745
|
name: 'model',
|
|
1746
1746
|
datasource: 'memory',
|
|
1747
1747
|
properties: {
|
|
@@ -1759,7 +1759,7 @@ describe('MemoryAdapter', function () {
|
|
|
1759
1759
|
},
|
|
1760
1760
|
},
|
|
1761
1761
|
});
|
|
1762
|
-
const adapter = new MemoryAdapter(
|
|
1762
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1763
1763
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
1764
1764
|
const filter = {fields: ['foo', 'bar']};
|
|
1765
1765
|
const result = await adapter.replaceOrCreate('model', input, filter);
|
|
@@ -1771,12 +1771,12 @@ describe('MemoryAdapter', function () {
|
|
|
1771
1771
|
});
|
|
1772
1772
|
|
|
1773
1773
|
it('removes properties when replacing an item by a given identifier', async function () {
|
|
1774
|
-
const
|
|
1775
|
-
|
|
1774
|
+
const dbs = new DatabaseSchema();
|
|
1775
|
+
dbs.defineDatasource({
|
|
1776
1776
|
name: 'memory',
|
|
1777
1777
|
adapter: 'memory',
|
|
1778
1778
|
});
|
|
1779
|
-
|
|
1779
|
+
dbs.defineModel({
|
|
1780
1780
|
name: 'model',
|
|
1781
1781
|
datasource: 'memory',
|
|
1782
1782
|
properties: {
|
|
@@ -1784,7 +1784,7 @@ describe('MemoryAdapter', function () {
|
|
|
1784
1784
|
bar: DataType.NUMBER,
|
|
1785
1785
|
},
|
|
1786
1786
|
});
|
|
1787
|
-
const adapter = new MemoryAdapter(
|
|
1787
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1788
1788
|
const input = {foo: 1, bar: 2};
|
|
1789
1789
|
const created = await adapter.create('model', input);
|
|
1790
1790
|
const idValue = created[DEF_PK];
|
|
@@ -1798,12 +1798,12 @@ describe('MemoryAdapter', function () {
|
|
|
1798
1798
|
});
|
|
1799
1799
|
|
|
1800
1800
|
it('sets a default values for removed properties when replacing an item', async function () {
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1801
|
+
const dbs = new DatabaseSchema();
|
|
1802
|
+
dbs.defineDatasource({
|
|
1803
1803
|
name: 'memory',
|
|
1804
1804
|
adapter: 'memory',
|
|
1805
1805
|
});
|
|
1806
|
-
|
|
1806
|
+
dbs.defineModel({
|
|
1807
1807
|
name: 'model',
|
|
1808
1808
|
datasource: 'memory',
|
|
1809
1809
|
properties: {
|
|
@@ -1817,7 +1817,7 @@ describe('MemoryAdapter', function () {
|
|
|
1817
1817
|
},
|
|
1818
1818
|
},
|
|
1819
1819
|
});
|
|
1820
|
-
const adapter = new MemoryAdapter(
|
|
1820
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1821
1821
|
const created = await adapter.create('model', {});
|
|
1822
1822
|
const idValue = created[DEF_PK];
|
|
1823
1823
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1831,12 +1831,12 @@ describe('MemoryAdapter', function () {
|
|
|
1831
1831
|
});
|
|
1832
1832
|
|
|
1833
1833
|
it('sets a default values for replaced properties with an undefined value', async function () {
|
|
1834
|
-
const
|
|
1835
|
-
|
|
1834
|
+
const dbs = new DatabaseSchema();
|
|
1835
|
+
dbs.defineDatasource({
|
|
1836
1836
|
name: 'memory',
|
|
1837
1837
|
adapter: 'memory',
|
|
1838
1838
|
});
|
|
1839
|
-
|
|
1839
|
+
dbs.defineModel({
|
|
1840
1840
|
name: 'model',
|
|
1841
1841
|
datasource: 'memory',
|
|
1842
1842
|
properties: {
|
|
@@ -1850,7 +1850,7 @@ describe('MemoryAdapter', function () {
|
|
|
1850
1850
|
},
|
|
1851
1851
|
},
|
|
1852
1852
|
});
|
|
1853
|
-
const adapter = new MemoryAdapter(
|
|
1853
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1854
1854
|
const created = await adapter.create('model', {});
|
|
1855
1855
|
const idValue = created[DEF_PK];
|
|
1856
1856
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1866,12 +1866,12 @@ describe('MemoryAdapter', function () {
|
|
|
1866
1866
|
});
|
|
1867
1867
|
|
|
1868
1868
|
it('sets a default values for replaced properties with a null value', async function () {
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1869
|
+
const dbs = new DatabaseSchema();
|
|
1870
|
+
dbs.defineDatasource({
|
|
1871
1871
|
name: 'memory',
|
|
1872
1872
|
adapter: 'memory',
|
|
1873
1873
|
});
|
|
1874
|
-
|
|
1874
|
+
dbs.defineModel({
|
|
1875
1875
|
name: 'model',
|
|
1876
1876
|
datasource: 'memory',
|
|
1877
1877
|
properties: {
|
|
@@ -1885,7 +1885,7 @@ describe('MemoryAdapter', function () {
|
|
|
1885
1885
|
},
|
|
1886
1886
|
},
|
|
1887
1887
|
});
|
|
1888
|
-
const adapter = new MemoryAdapter(
|
|
1888
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1889
1889
|
const created = await adapter.create('model', {});
|
|
1890
1890
|
const idValue = created[DEF_PK];
|
|
1891
1891
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -1903,12 +1903,12 @@ describe('MemoryAdapter', function () {
|
|
|
1903
1903
|
|
|
1904
1904
|
describe('patch', function () {
|
|
1905
1905
|
it('updates only provided properties for all items and returns their number', async function () {
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1906
|
+
const dbs = new DatabaseSchema();
|
|
1907
|
+
dbs.defineDatasource({
|
|
1908
1908
|
name: 'memory',
|
|
1909
1909
|
adapter: 'memory',
|
|
1910
1910
|
});
|
|
1911
|
-
|
|
1911
|
+
dbs.defineModel({
|
|
1912
1912
|
name: 'model',
|
|
1913
1913
|
datasource: 'memory',
|
|
1914
1914
|
properties: {
|
|
@@ -1916,7 +1916,7 @@ describe('MemoryAdapter', function () {
|
|
|
1916
1916
|
bar: DataType.STRING,
|
|
1917
1917
|
},
|
|
1918
1918
|
});
|
|
1919
|
-
const adapter = new MemoryAdapter(
|
|
1919
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1920
1920
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
1921
1921
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
1922
1922
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -1944,12 +1944,12 @@ describe('MemoryAdapter', function () {
|
|
|
1944
1944
|
});
|
|
1945
1945
|
|
|
1946
1946
|
it('does not throw an error if a partial data does not have required property', async function () {
|
|
1947
|
-
const
|
|
1948
|
-
|
|
1947
|
+
const dbs = new DatabaseSchema();
|
|
1948
|
+
dbs.defineDatasource({
|
|
1949
1949
|
name: 'memory',
|
|
1950
1950
|
adapter: 'memory',
|
|
1951
1951
|
});
|
|
1952
|
-
|
|
1952
|
+
dbs.defineModel({
|
|
1953
1953
|
name: 'model',
|
|
1954
1954
|
datasource: 'memory',
|
|
1955
1955
|
properties: {
|
|
@@ -1960,7 +1960,7 @@ describe('MemoryAdapter', function () {
|
|
|
1960
1960
|
},
|
|
1961
1961
|
},
|
|
1962
1962
|
});
|
|
1963
|
-
const adapter = new MemoryAdapter(
|
|
1963
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
1964
1964
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
1965
1965
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
1966
1966
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -1988,12 +1988,12 @@ describe('MemoryAdapter', function () {
|
|
|
1988
1988
|
});
|
|
1989
1989
|
|
|
1990
1990
|
it('ignores identifier value in a given data in case of a default primary key', async function () {
|
|
1991
|
-
const
|
|
1992
|
-
|
|
1991
|
+
const dbs = new DatabaseSchema();
|
|
1992
|
+
dbs.defineDatasource({
|
|
1993
1993
|
name: 'memory',
|
|
1994
1994
|
adapter: 'memory',
|
|
1995
1995
|
});
|
|
1996
|
-
|
|
1996
|
+
dbs.defineModel({
|
|
1997
1997
|
name: 'model',
|
|
1998
1998
|
datasource: 'memory',
|
|
1999
1999
|
properties: {
|
|
@@ -2001,7 +2001,7 @@ describe('MemoryAdapter', function () {
|
|
|
2001
2001
|
bar: DataType.STRING,
|
|
2002
2002
|
},
|
|
2003
2003
|
});
|
|
2004
|
-
const adapter = new MemoryAdapter(
|
|
2004
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2005
2005
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2006
2006
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2007
2007
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2029,12 +2029,12 @@ describe('MemoryAdapter', function () {
|
|
|
2029
2029
|
});
|
|
2030
2030
|
|
|
2031
2031
|
it('ignores identifier value in a given data in case of a specified primary key', async function () {
|
|
2032
|
-
const
|
|
2033
|
-
|
|
2032
|
+
const dbs = new DatabaseSchema();
|
|
2033
|
+
dbs.defineDatasource({
|
|
2034
2034
|
name: 'memory',
|
|
2035
2035
|
adapter: 'memory',
|
|
2036
2036
|
});
|
|
2037
|
-
|
|
2037
|
+
dbs.defineModel({
|
|
2038
2038
|
name: 'model',
|
|
2039
2039
|
datasource: 'memory',
|
|
2040
2040
|
properties: {
|
|
@@ -2046,7 +2046,7 @@ describe('MemoryAdapter', function () {
|
|
|
2046
2046
|
bar: DataType.STRING,
|
|
2047
2047
|
},
|
|
2048
2048
|
});
|
|
2049
|
-
const adapter = new MemoryAdapter(
|
|
2049
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2050
2050
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2051
2051
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2052
2052
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2074,12 +2074,12 @@ describe('MemoryAdapter', function () {
|
|
|
2074
2074
|
});
|
|
2075
2075
|
|
|
2076
2076
|
it('sets a default values for patched properties with an undefined value', async function () {
|
|
2077
|
-
const
|
|
2078
|
-
|
|
2077
|
+
const dbs = new DatabaseSchema();
|
|
2078
|
+
dbs.defineDatasource({
|
|
2079
2079
|
name: 'memory',
|
|
2080
2080
|
adapter: 'memory',
|
|
2081
2081
|
});
|
|
2082
|
-
|
|
2082
|
+
dbs.defineModel({
|
|
2083
2083
|
name: 'model',
|
|
2084
2084
|
datasource: 'memory',
|
|
2085
2085
|
properties: {
|
|
@@ -2093,7 +2093,7 @@ describe('MemoryAdapter', function () {
|
|
|
2093
2093
|
},
|
|
2094
2094
|
},
|
|
2095
2095
|
});
|
|
2096
|
-
const adapter = new MemoryAdapter(
|
|
2096
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2097
2097
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2098
2098
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2099
2099
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2121,12 +2121,12 @@ describe('MemoryAdapter', function () {
|
|
|
2121
2121
|
});
|
|
2122
2122
|
|
|
2123
2123
|
it('sets a default values for patched properties with a null value', async function () {
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2124
|
+
const dbs = new DatabaseSchema();
|
|
2125
|
+
dbs.defineDatasource({
|
|
2126
2126
|
name: 'memory',
|
|
2127
2127
|
adapter: 'memory',
|
|
2128
2128
|
});
|
|
2129
|
-
|
|
2129
|
+
dbs.defineModel({
|
|
2130
2130
|
name: 'model',
|
|
2131
2131
|
datasource: 'memory',
|
|
2132
2132
|
properties: {
|
|
@@ -2140,7 +2140,7 @@ describe('MemoryAdapter', function () {
|
|
|
2140
2140
|
},
|
|
2141
2141
|
},
|
|
2142
2142
|
});
|
|
2143
|
-
const adapter = new MemoryAdapter(
|
|
2143
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2144
2144
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2145
2145
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2146
2146
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2168,12 +2168,12 @@ describe('MemoryAdapter', function () {
|
|
|
2168
2168
|
});
|
|
2169
2169
|
|
|
2170
2170
|
it('uses a specified column name for a regular property', async function () {
|
|
2171
|
-
const
|
|
2172
|
-
|
|
2171
|
+
const dbs = new DatabaseSchema();
|
|
2172
|
+
dbs.defineDatasource({
|
|
2173
2173
|
name: 'memory',
|
|
2174
2174
|
adapter: 'memory',
|
|
2175
2175
|
});
|
|
2176
|
-
|
|
2176
|
+
dbs.defineModel({
|
|
2177
2177
|
name: 'model',
|
|
2178
2178
|
datasource: 'memory',
|
|
2179
2179
|
properties: {
|
|
@@ -2187,7 +2187,7 @@ describe('MemoryAdapter', function () {
|
|
|
2187
2187
|
},
|
|
2188
2188
|
},
|
|
2189
2189
|
});
|
|
2190
|
-
const adapter = new MemoryAdapter(
|
|
2190
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2191
2191
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2192
2192
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2193
2193
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2215,12 +2215,12 @@ describe('MemoryAdapter', function () {
|
|
|
2215
2215
|
});
|
|
2216
2216
|
|
|
2217
2217
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2218
|
+
const dbs = new DatabaseSchema();
|
|
2219
|
+
dbs.defineDatasource({
|
|
2220
2220
|
name: 'memory',
|
|
2221
2221
|
adapter: 'memory',
|
|
2222
2222
|
});
|
|
2223
|
-
|
|
2223
|
+
dbs.defineModel({
|
|
2224
2224
|
name: 'model',
|
|
2225
2225
|
datasource: 'memory',
|
|
2226
2226
|
properties: {
|
|
@@ -2236,7 +2236,7 @@ describe('MemoryAdapter', function () {
|
|
|
2236
2236
|
},
|
|
2237
2237
|
},
|
|
2238
2238
|
});
|
|
2239
|
-
const adapter = new MemoryAdapter(
|
|
2239
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2240
2240
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2241
2241
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2242
2242
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2264,12 +2264,12 @@ describe('MemoryAdapter', function () {
|
|
|
2264
2264
|
});
|
|
2265
2265
|
|
|
2266
2266
|
it('returns zero if nothing matched by the "where" clause', async function () {
|
|
2267
|
-
const
|
|
2268
|
-
|
|
2267
|
+
const dbs = new DatabaseSchema();
|
|
2268
|
+
dbs.defineDatasource({
|
|
2269
2269
|
name: 'memory',
|
|
2270
2270
|
adapter: 'memory',
|
|
2271
2271
|
});
|
|
2272
|
-
|
|
2272
|
+
dbs.defineModel({
|
|
2273
2273
|
name: 'model',
|
|
2274
2274
|
datasource: 'memory',
|
|
2275
2275
|
properties: {
|
|
@@ -2277,7 +2277,7 @@ describe('MemoryAdapter', function () {
|
|
|
2277
2277
|
bar: DataType.STRING,
|
|
2278
2278
|
},
|
|
2279
2279
|
});
|
|
2280
|
-
const adapter = new MemoryAdapter(
|
|
2280
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2281
2281
|
const input1 = {foo: 'a1', bar: 'a2'};
|
|
2282
2282
|
const input2 = {foo: 'b1', bar: 'b2'};
|
|
2283
2283
|
const input3 = {foo: 'c1', bar: 'c2'};
|
|
@@ -2305,12 +2305,12 @@ describe('MemoryAdapter', function () {
|
|
|
2305
2305
|
});
|
|
2306
2306
|
|
|
2307
2307
|
it('uses the "where" clause to patch specific items', async function () {
|
|
2308
|
-
const
|
|
2309
|
-
|
|
2308
|
+
const dbs = new DatabaseSchema();
|
|
2309
|
+
dbs.defineDatasource({
|
|
2310
2310
|
name: 'memory',
|
|
2311
2311
|
adapter: 'memory',
|
|
2312
2312
|
});
|
|
2313
|
-
|
|
2313
|
+
dbs.defineModel({
|
|
2314
2314
|
name: 'model',
|
|
2315
2315
|
datasource: 'memory',
|
|
2316
2316
|
properties: {
|
|
@@ -2318,7 +2318,7 @@ describe('MemoryAdapter', function () {
|
|
|
2318
2318
|
bar: DataType.STRING,
|
|
2319
2319
|
},
|
|
2320
2320
|
});
|
|
2321
|
-
const adapter = new MemoryAdapter(
|
|
2321
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2322
2322
|
const input1 = {foo: 'a', bar: '1'};
|
|
2323
2323
|
const input2 = {foo: 'b', bar: '2'};
|
|
2324
2324
|
const input3 = {foo: 'c', bar: '2'};
|
|
@@ -2346,12 +2346,12 @@ describe('MemoryAdapter', function () {
|
|
|
2346
2346
|
});
|
|
2347
2347
|
|
|
2348
2348
|
it('the "where" clause uses property names instead of column names', async function () {
|
|
2349
|
-
const
|
|
2350
|
-
|
|
2349
|
+
const dbs = new DatabaseSchema();
|
|
2350
|
+
dbs.defineDatasource({
|
|
2351
2351
|
name: 'memory',
|
|
2352
2352
|
adapter: 'memory',
|
|
2353
2353
|
});
|
|
2354
|
-
|
|
2354
|
+
dbs.defineModel({
|
|
2355
2355
|
name: 'model',
|
|
2356
2356
|
datasource: 'memory',
|
|
2357
2357
|
properties: {
|
|
@@ -2365,7 +2365,7 @@ describe('MemoryAdapter', function () {
|
|
|
2365
2365
|
},
|
|
2366
2366
|
},
|
|
2367
2367
|
});
|
|
2368
|
-
const adapter = new MemoryAdapter(
|
|
2368
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2369
2369
|
const input1 = {foo: 'a', bar: '1'};
|
|
2370
2370
|
const input2 = {foo: 'b', bar: '2'};
|
|
2371
2371
|
const input3 = {foo: 'c', bar: '2'};
|
|
@@ -2393,12 +2393,12 @@ describe('MemoryAdapter', function () {
|
|
|
2393
2393
|
});
|
|
2394
2394
|
|
|
2395
2395
|
it('the "where" clause uses a persisted data instead of default values in case of undefined', async function () {
|
|
2396
|
-
const
|
|
2397
|
-
|
|
2396
|
+
const dbs = new DatabaseSchema();
|
|
2397
|
+
dbs.defineDatasource({
|
|
2398
2398
|
name: 'memory',
|
|
2399
2399
|
adapter: 'memory',
|
|
2400
2400
|
});
|
|
2401
|
-
|
|
2401
|
+
dbs.defineModel({
|
|
2402
2402
|
name: 'model',
|
|
2403
2403
|
datasource: 'memory',
|
|
2404
2404
|
properties: {
|
|
@@ -2409,7 +2409,7 @@ describe('MemoryAdapter', function () {
|
|
|
2409
2409
|
},
|
|
2410
2410
|
},
|
|
2411
2411
|
});
|
|
2412
|
-
const adapter = new MemoryAdapter(
|
|
2412
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2413
2413
|
const input1 = {[DEF_PK]: 1, foo: 'a', bar: undefined};
|
|
2414
2414
|
const input2 = {[DEF_PK]: 2, foo: 'b', bar: undefined};
|
|
2415
2415
|
const input3 = {[DEF_PK]: 3, foo: 'c', bar: 10};
|
|
@@ -2431,12 +2431,12 @@ describe('MemoryAdapter', function () {
|
|
|
2431
2431
|
});
|
|
2432
2432
|
|
|
2433
2433
|
it('the "where" clause uses a persisted data instead of default values in case of null', async function () {
|
|
2434
|
-
const
|
|
2435
|
-
|
|
2434
|
+
const dbs = new DatabaseSchema();
|
|
2435
|
+
dbs.defineDatasource({
|
|
2436
2436
|
name: 'memory',
|
|
2437
2437
|
adapter: 'memory',
|
|
2438
2438
|
});
|
|
2439
|
-
|
|
2439
|
+
dbs.defineModel({
|
|
2440
2440
|
name: 'model',
|
|
2441
2441
|
datasource: 'memory',
|
|
2442
2442
|
properties: {
|
|
@@ -2447,7 +2447,7 @@ describe('MemoryAdapter', function () {
|
|
|
2447
2447
|
},
|
|
2448
2448
|
},
|
|
2449
2449
|
});
|
|
2450
|
-
const adapter = new MemoryAdapter(
|
|
2450
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2451
2451
|
const input1 = {[DEF_PK]: 1, foo: 'a', bar: undefined};
|
|
2452
2452
|
const input2 = {[DEF_PK]: 2, foo: 'b', bar: undefined};
|
|
2453
2453
|
const input3 = {[DEF_PK]: 3, foo: 'c', bar: 10};
|
|
@@ -2471,12 +2471,12 @@ describe('MemoryAdapter', function () {
|
|
|
2471
2471
|
|
|
2472
2472
|
describe('patchById', function () {
|
|
2473
2473
|
it('updates only provided properties by a given identifier', async function () {
|
|
2474
|
-
const
|
|
2475
|
-
|
|
2474
|
+
const dbs = new DatabaseSchema();
|
|
2475
|
+
dbs.defineDatasource({
|
|
2476
2476
|
name: 'memory',
|
|
2477
2477
|
adapter: 'memory',
|
|
2478
2478
|
});
|
|
2479
|
-
|
|
2479
|
+
dbs.defineModel({
|
|
2480
2480
|
name: 'model',
|
|
2481
2481
|
datasource: 'memory',
|
|
2482
2482
|
properties: {
|
|
@@ -2484,7 +2484,7 @@ describe('MemoryAdapter', function () {
|
|
|
2484
2484
|
bar: DataType.NUMBER,
|
|
2485
2485
|
},
|
|
2486
2486
|
});
|
|
2487
|
-
const adapter = new MemoryAdapter(
|
|
2487
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2488
2488
|
const input = {foo: 1, bar: 2};
|
|
2489
2489
|
const createdModelData = await adapter.create('model', input);
|
|
2490
2490
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2508,12 +2508,12 @@ describe('MemoryAdapter', function () {
|
|
|
2508
2508
|
});
|
|
2509
2509
|
|
|
2510
2510
|
it('does not throw an error if a partial data does not have required property', async function () {
|
|
2511
|
-
const
|
|
2512
|
-
|
|
2511
|
+
const dbs = new DatabaseSchema();
|
|
2512
|
+
dbs.defineDatasource({
|
|
2513
2513
|
name: 'memory',
|
|
2514
2514
|
adapter: 'memory',
|
|
2515
2515
|
});
|
|
2516
|
-
|
|
2516
|
+
dbs.defineModel({
|
|
2517
2517
|
name: 'model',
|
|
2518
2518
|
datasource: 'memory',
|
|
2519
2519
|
properties: {
|
|
@@ -2524,7 +2524,7 @@ describe('MemoryAdapter', function () {
|
|
|
2524
2524
|
bar: DataType.NUMBER,
|
|
2525
2525
|
},
|
|
2526
2526
|
});
|
|
2527
|
-
const adapter = new MemoryAdapter(
|
|
2527
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2528
2528
|
const input = {foo: 1, bar: 2};
|
|
2529
2529
|
const createdModelData = await adapter.create('model', input);
|
|
2530
2530
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2548,16 +2548,16 @@ describe('MemoryAdapter', function () {
|
|
|
2548
2548
|
});
|
|
2549
2549
|
|
|
2550
2550
|
it('ignores identifier value in a given data in case of a default primary key', async function () {
|
|
2551
|
-
const
|
|
2552
|
-
|
|
2551
|
+
const dbs = new DatabaseSchema();
|
|
2552
|
+
dbs.defineDatasource({
|
|
2553
2553
|
name: 'memory',
|
|
2554
2554
|
adapter: 'memory',
|
|
2555
2555
|
});
|
|
2556
|
-
|
|
2556
|
+
dbs.defineModel({
|
|
2557
2557
|
name: 'model',
|
|
2558
2558
|
datasource: 'memory',
|
|
2559
2559
|
});
|
|
2560
|
-
const adapter = new MemoryAdapter(
|
|
2560
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2561
2561
|
const idValue = 10;
|
|
2562
2562
|
const createdModelData = await adapter.create('model', {
|
|
2563
2563
|
[DEF_PK]: idValue,
|
|
@@ -2575,12 +2575,12 @@ describe('MemoryAdapter', function () {
|
|
|
2575
2575
|
});
|
|
2576
2576
|
|
|
2577
2577
|
it('ignores identifier value in a given data in case of a specified primary key', async function () {
|
|
2578
|
-
const
|
|
2579
|
-
|
|
2578
|
+
const dbs = new DatabaseSchema();
|
|
2579
|
+
dbs.defineDatasource({
|
|
2580
2580
|
name: 'memory',
|
|
2581
2581
|
adapter: 'memory',
|
|
2582
2582
|
});
|
|
2583
|
-
|
|
2583
|
+
dbs.defineModel({
|
|
2584
2584
|
name: 'model',
|
|
2585
2585
|
datasource: 'memory',
|
|
2586
2586
|
properties: {
|
|
@@ -2590,7 +2590,7 @@ describe('MemoryAdapter', function () {
|
|
|
2590
2590
|
},
|
|
2591
2591
|
},
|
|
2592
2592
|
});
|
|
2593
|
-
const adapter = new MemoryAdapter(
|
|
2593
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2594
2594
|
const idValue = 10;
|
|
2595
2595
|
const createdModelData = await adapter.create('model', {myId: idValue});
|
|
2596
2596
|
expect(createdModelData).to.be.eql({myId: idValue});
|
|
@@ -2606,12 +2606,12 @@ describe('MemoryAdapter', function () {
|
|
|
2606
2606
|
});
|
|
2607
2607
|
|
|
2608
2608
|
it('sets a default values for patched properties with an undefined value', async function () {
|
|
2609
|
-
const
|
|
2610
|
-
|
|
2609
|
+
const dbs = new DatabaseSchema();
|
|
2610
|
+
dbs.defineDatasource({
|
|
2611
2611
|
name: 'memory',
|
|
2612
2612
|
adapter: 'memory',
|
|
2613
2613
|
});
|
|
2614
|
-
|
|
2614
|
+
dbs.defineModel({
|
|
2615
2615
|
name: 'model',
|
|
2616
2616
|
datasource: 'memory',
|
|
2617
2617
|
properties: {
|
|
@@ -2625,7 +2625,7 @@ describe('MemoryAdapter', function () {
|
|
|
2625
2625
|
},
|
|
2626
2626
|
},
|
|
2627
2627
|
});
|
|
2628
|
-
const adapter = new MemoryAdapter(
|
|
2628
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2629
2629
|
const createdModelData = await adapter.create('model', {});
|
|
2630
2630
|
const idValue = createdModelData[DEF_PK];
|
|
2631
2631
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -2642,12 +2642,12 @@ describe('MemoryAdapter', function () {
|
|
|
2642
2642
|
});
|
|
2643
2643
|
|
|
2644
2644
|
it('sets a default values for patched properties with a null value', async function () {
|
|
2645
|
-
const
|
|
2646
|
-
|
|
2645
|
+
const dbs = new DatabaseSchema();
|
|
2646
|
+
dbs.defineDatasource({
|
|
2647
2647
|
name: 'memory',
|
|
2648
2648
|
adapter: 'memory',
|
|
2649
2649
|
});
|
|
2650
|
-
|
|
2650
|
+
dbs.defineModel({
|
|
2651
2651
|
name: 'model',
|
|
2652
2652
|
datasource: 'memory',
|
|
2653
2653
|
properties: {
|
|
@@ -2661,7 +2661,7 @@ describe('MemoryAdapter', function () {
|
|
|
2661
2661
|
},
|
|
2662
2662
|
},
|
|
2663
2663
|
});
|
|
2664
|
-
const adapter = new MemoryAdapter(
|
|
2664
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2665
2665
|
const createdModelData = await adapter.create('model', {});
|
|
2666
2666
|
const idValue = createdModelData[DEF_PK];
|
|
2667
2667
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -2678,12 +2678,12 @@ describe('MemoryAdapter', function () {
|
|
|
2678
2678
|
});
|
|
2679
2679
|
|
|
2680
2680
|
it('throws an error if a given identifier does not exist', async function () {
|
|
2681
|
-
const
|
|
2682
|
-
|
|
2681
|
+
const dbs = new DatabaseSchema();
|
|
2682
|
+
dbs.defineDatasource({
|
|
2683
2683
|
name: 'memory',
|
|
2684
2684
|
adapter: 'memory',
|
|
2685
2685
|
});
|
|
2686
|
-
|
|
2686
|
+
dbs.defineModel({
|
|
2687
2687
|
name: 'model',
|
|
2688
2688
|
datasource: 'memory',
|
|
2689
2689
|
properties: {
|
|
@@ -2691,7 +2691,7 @@ describe('MemoryAdapter', function () {
|
|
|
2691
2691
|
bar: DataType.NUMBER,
|
|
2692
2692
|
},
|
|
2693
2693
|
});
|
|
2694
|
-
const adapter = new MemoryAdapter(
|
|
2694
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2695
2695
|
const promise = adapter.patchById('model', 1, {foo: 2});
|
|
2696
2696
|
await expect(promise).to.be.rejectedWith(
|
|
2697
2697
|
format(
|
|
@@ -2702,12 +2702,12 @@ describe('MemoryAdapter', function () {
|
|
|
2702
2702
|
});
|
|
2703
2703
|
|
|
2704
2704
|
it('uses a specified column name for a primary key', async function () {
|
|
2705
|
-
const
|
|
2706
|
-
|
|
2705
|
+
const dbs = new DatabaseSchema();
|
|
2706
|
+
dbs.defineDatasource({
|
|
2707
2707
|
name: 'memory',
|
|
2708
2708
|
adapter: 'memory',
|
|
2709
2709
|
});
|
|
2710
|
-
|
|
2710
|
+
dbs.defineModel({
|
|
2711
2711
|
name: 'model',
|
|
2712
2712
|
datasource: 'memory',
|
|
2713
2713
|
properties: {
|
|
@@ -2720,7 +2720,7 @@ describe('MemoryAdapter', function () {
|
|
|
2720
2720
|
baz: DataType.NUMBER,
|
|
2721
2721
|
},
|
|
2722
2722
|
});
|
|
2723
|
-
const adapter = new MemoryAdapter(
|
|
2723
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2724
2724
|
const input = {bar: 1, baz: 2};
|
|
2725
2725
|
const createdModelData = await adapter.create('model', input);
|
|
2726
2726
|
expect(createdModelData).to.be.eql({foo: createdModelData.foo, ...input});
|
|
@@ -2747,12 +2747,12 @@ describe('MemoryAdapter', function () {
|
|
|
2747
2747
|
});
|
|
2748
2748
|
|
|
2749
2749
|
it('uses a specified column name for a regular property', async function () {
|
|
2750
|
-
const
|
|
2751
|
-
|
|
2750
|
+
const dbs = new DatabaseSchema();
|
|
2751
|
+
dbs.defineDatasource({
|
|
2752
2752
|
name: 'memory',
|
|
2753
2753
|
adapter: 'memory',
|
|
2754
2754
|
});
|
|
2755
|
-
|
|
2755
|
+
dbs.defineModel({
|
|
2756
2756
|
name: 'model',
|
|
2757
2757
|
datasource: 'memory',
|
|
2758
2758
|
properties: {
|
|
@@ -2763,7 +2763,7 @@ describe('MemoryAdapter', function () {
|
|
|
2763
2763
|
bar: DataType.NUMBER,
|
|
2764
2764
|
},
|
|
2765
2765
|
});
|
|
2766
|
-
const adapter = new MemoryAdapter(
|
|
2766
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2767
2767
|
const input = {foo: 1, bar: 2};
|
|
2768
2768
|
const createdModelData = await adapter.create('model', input);
|
|
2769
2769
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2795,12 +2795,12 @@ describe('MemoryAdapter', function () {
|
|
|
2795
2795
|
});
|
|
2796
2796
|
|
|
2797
2797
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
2798
|
-
const
|
|
2799
|
-
|
|
2798
|
+
const dbs = new DatabaseSchema();
|
|
2799
|
+
dbs.defineDatasource({
|
|
2800
2800
|
name: 'memory',
|
|
2801
2801
|
adapter: 'memory',
|
|
2802
2802
|
});
|
|
2803
|
-
|
|
2803
|
+
dbs.defineModel({
|
|
2804
2804
|
name: 'model',
|
|
2805
2805
|
datasource: 'memory',
|
|
2806
2806
|
properties: {
|
|
@@ -2815,7 +2815,7 @@ describe('MemoryAdapter', function () {
|
|
|
2815
2815
|
},
|
|
2816
2816
|
},
|
|
2817
2817
|
});
|
|
2818
|
-
const adapter = new MemoryAdapter(
|
|
2818
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2819
2819
|
const createdModelData = await adapter.create('model', {});
|
|
2820
2820
|
const idValue = createdModelData[DEF_PK];
|
|
2821
2821
|
const defaults = {foo: 1, bar: 2};
|
|
@@ -2847,12 +2847,12 @@ describe('MemoryAdapter', function () {
|
|
|
2847
2847
|
});
|
|
2848
2848
|
|
|
2849
2849
|
it('allows to specify a short form of a fields clause to filter a return value', async function () {
|
|
2850
|
-
const
|
|
2851
|
-
|
|
2850
|
+
const dbs = new DatabaseSchema();
|
|
2851
|
+
dbs.defineDatasource({
|
|
2852
2852
|
name: 'memory',
|
|
2853
2853
|
adapter: 'memory',
|
|
2854
2854
|
});
|
|
2855
|
-
|
|
2855
|
+
dbs.defineModel({
|
|
2856
2856
|
name: 'model',
|
|
2857
2857
|
datasource: 'memory',
|
|
2858
2858
|
properties: {
|
|
@@ -2860,7 +2860,7 @@ describe('MemoryAdapter', function () {
|
|
|
2860
2860
|
bar: DataType.NUMBER,
|
|
2861
2861
|
},
|
|
2862
2862
|
});
|
|
2863
|
-
const adapter = new MemoryAdapter(
|
|
2863
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2864
2864
|
const input = {foo: 'string', bar: 10};
|
|
2865
2865
|
const createdModelData = await adapter.create('model', input);
|
|
2866
2866
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2883,12 +2883,12 @@ describe('MemoryAdapter', function () {
|
|
|
2883
2883
|
});
|
|
2884
2884
|
|
|
2885
2885
|
it('allows to specify a full form of a fields clause to filter a return value', async function () {
|
|
2886
|
-
const
|
|
2887
|
-
|
|
2886
|
+
const dbs = new DatabaseSchema();
|
|
2887
|
+
dbs.defineDatasource({
|
|
2888
2888
|
name: 'memory',
|
|
2889
2889
|
adapter: 'memory',
|
|
2890
2890
|
});
|
|
2891
|
-
|
|
2891
|
+
dbs.defineModel({
|
|
2892
2892
|
name: 'model',
|
|
2893
2893
|
datasource: 'memory',
|
|
2894
2894
|
properties: {
|
|
@@ -2897,7 +2897,7 @@ describe('MemoryAdapter', function () {
|
|
|
2897
2897
|
baz: DataType.BOOLEAN,
|
|
2898
2898
|
},
|
|
2899
2899
|
});
|
|
2900
|
-
const adapter = new MemoryAdapter(
|
|
2900
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2901
2901
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
2902
2902
|
const createdModelData = await adapter.create('model', input);
|
|
2903
2903
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2921,12 +2921,12 @@ describe('MemoryAdapter', function () {
|
|
|
2921
2921
|
});
|
|
2922
2922
|
|
|
2923
2923
|
it('a fields clause uses property names instead of column names', async function () {
|
|
2924
|
-
const
|
|
2925
|
-
|
|
2924
|
+
const dbs = new DatabaseSchema();
|
|
2925
|
+
dbs.defineDatasource({
|
|
2926
2926
|
name: 'memory',
|
|
2927
2927
|
adapter: 'memory',
|
|
2928
2928
|
});
|
|
2929
|
-
|
|
2929
|
+
dbs.defineModel({
|
|
2930
2930
|
name: 'model',
|
|
2931
2931
|
datasource: 'memory',
|
|
2932
2932
|
properties: {
|
|
@@ -2944,7 +2944,7 @@ describe('MemoryAdapter', function () {
|
|
|
2944
2944
|
},
|
|
2945
2945
|
},
|
|
2946
2946
|
});
|
|
2947
|
-
const adapter = new MemoryAdapter(
|
|
2947
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2948
2948
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
2949
2949
|
const createdModelData = await adapter.create('model', input);
|
|
2950
2950
|
const idValue = createdModelData[DEF_PK];
|
|
@@ -2980,32 +2980,32 @@ describe('MemoryAdapter', function () {
|
|
|
2980
2980
|
|
|
2981
2981
|
describe('find', function () {
|
|
2982
2982
|
it('returns an empty array if a table does not have an items', async function () {
|
|
2983
|
-
const
|
|
2984
|
-
|
|
2983
|
+
const dbs = new DatabaseSchema();
|
|
2984
|
+
dbs.defineDatasource({
|
|
2985
2985
|
name: 'memory',
|
|
2986
2986
|
adapter: 'memory',
|
|
2987
2987
|
});
|
|
2988
|
-
|
|
2988
|
+
dbs.defineModel({
|
|
2989
2989
|
name: 'model',
|
|
2990
2990
|
datasource: 'memory',
|
|
2991
2991
|
});
|
|
2992
|
-
const adapter = new MemoryAdapter(
|
|
2992
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
2993
2993
|
const result = await adapter.find('model');
|
|
2994
2994
|
expect(result).to.be.instanceof(Array);
|
|
2995
2995
|
expect(result).to.be.empty;
|
|
2996
2996
|
});
|
|
2997
2997
|
|
|
2998
2998
|
it('returns an array of table items', async function () {
|
|
2999
|
-
const
|
|
3000
|
-
|
|
2999
|
+
const dbs = new DatabaseSchema();
|
|
3000
|
+
dbs.defineDatasource({
|
|
3001
3001
|
name: 'memory',
|
|
3002
3002
|
adapter: 'memory',
|
|
3003
3003
|
});
|
|
3004
|
-
|
|
3004
|
+
dbs.defineModel({
|
|
3005
3005
|
name: 'model',
|
|
3006
3006
|
datasource: 'memory',
|
|
3007
3007
|
});
|
|
3008
|
-
const adapter = new MemoryAdapter(
|
|
3008
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3009
3009
|
await adapter.create('model', {});
|
|
3010
3010
|
await adapter.create('model', {});
|
|
3011
3011
|
await adapter.create('model', {});
|
|
@@ -3018,12 +3018,12 @@ describe('MemoryAdapter', function () {
|
|
|
3018
3018
|
});
|
|
3019
3019
|
|
|
3020
3020
|
it('uses default values for non-existent properties', async function () {
|
|
3021
|
-
const
|
|
3022
|
-
|
|
3021
|
+
const dbs = new DatabaseSchema();
|
|
3022
|
+
dbs.defineDatasource({
|
|
3023
3023
|
name: 'memory',
|
|
3024
3024
|
adapter: 'memory',
|
|
3025
3025
|
});
|
|
3026
|
-
|
|
3026
|
+
dbs.defineModel({
|
|
3027
3027
|
name: 'model',
|
|
3028
3028
|
datasource: 'memory',
|
|
3029
3029
|
properties: {
|
|
@@ -3033,7 +3033,7 @@ describe('MemoryAdapter', function () {
|
|
|
3033
3033
|
},
|
|
3034
3034
|
},
|
|
3035
3035
|
});
|
|
3036
|
-
const adapter = new MemoryAdapter(
|
|
3036
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3037
3037
|
const table = adapter._getTableOrCreate('model');
|
|
3038
3038
|
table.set(1, {[DEF_PK]: 1});
|
|
3039
3039
|
table.set(2, {[DEF_PK]: 2});
|
|
@@ -3052,12 +3052,12 @@ describe('MemoryAdapter', function () {
|
|
|
3052
3052
|
});
|
|
3053
3053
|
|
|
3054
3054
|
it('uses default values for properties of an undefined', async function () {
|
|
3055
|
-
const
|
|
3056
|
-
|
|
3055
|
+
const dbs = new DatabaseSchema();
|
|
3056
|
+
dbs.defineDatasource({
|
|
3057
3057
|
name: 'memory',
|
|
3058
3058
|
adapter: 'memory',
|
|
3059
3059
|
});
|
|
3060
|
-
|
|
3060
|
+
dbs.defineModel({
|
|
3061
3061
|
name: 'model',
|
|
3062
3062
|
datasource: 'memory',
|
|
3063
3063
|
properties: {
|
|
@@ -3067,7 +3067,7 @@ describe('MemoryAdapter', function () {
|
|
|
3067
3067
|
},
|
|
3068
3068
|
},
|
|
3069
3069
|
});
|
|
3070
|
-
const adapter = new MemoryAdapter(
|
|
3070
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3071
3071
|
const table = adapter._getTableOrCreate('model');
|
|
3072
3072
|
table.set(1, {[DEF_PK]: 1, foo: undefined});
|
|
3073
3073
|
table.set(2, {[DEF_PK]: 2, foo: undefined});
|
|
@@ -3086,12 +3086,12 @@ describe('MemoryAdapter', function () {
|
|
|
3086
3086
|
});
|
|
3087
3087
|
|
|
3088
3088
|
it('uses default values for properties of a null', async function () {
|
|
3089
|
-
const
|
|
3090
|
-
|
|
3089
|
+
const dbs = new DatabaseSchema();
|
|
3090
|
+
dbs.defineDatasource({
|
|
3091
3091
|
name: 'memory',
|
|
3092
3092
|
adapter: 'memory',
|
|
3093
3093
|
});
|
|
3094
|
-
|
|
3094
|
+
dbs.defineModel({
|
|
3095
3095
|
name: 'model',
|
|
3096
3096
|
datasource: 'memory',
|
|
3097
3097
|
properties: {
|
|
@@ -3101,7 +3101,7 @@ describe('MemoryAdapter', function () {
|
|
|
3101
3101
|
},
|
|
3102
3102
|
},
|
|
3103
3103
|
});
|
|
3104
|
-
const adapter = new MemoryAdapter(
|
|
3104
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3105
3105
|
const table = adapter._getTableOrCreate('model');
|
|
3106
3106
|
table.set(1, {[DEF_PK]: 1, foo: null});
|
|
3107
3107
|
table.set(2, {[DEF_PK]: 2, foo: null});
|
|
@@ -3120,12 +3120,12 @@ describe('MemoryAdapter', function () {
|
|
|
3120
3120
|
});
|
|
3121
3121
|
|
|
3122
3122
|
it('allows to specify a short form of a fields clause to filter a return value', async function () {
|
|
3123
|
-
const
|
|
3124
|
-
|
|
3123
|
+
const dbs = new DatabaseSchema();
|
|
3124
|
+
dbs.defineDatasource({
|
|
3125
3125
|
name: 'memory',
|
|
3126
3126
|
adapter: 'memory',
|
|
3127
3127
|
});
|
|
3128
|
-
|
|
3128
|
+
dbs.defineModel({
|
|
3129
3129
|
name: 'model',
|
|
3130
3130
|
datasource: 'memory',
|
|
3131
3131
|
properties: {
|
|
@@ -3133,7 +3133,7 @@ describe('MemoryAdapter', function () {
|
|
|
3133
3133
|
bar: DataType.NUMBER,
|
|
3134
3134
|
},
|
|
3135
3135
|
});
|
|
3136
|
-
const adapter = new MemoryAdapter(
|
|
3136
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3137
3137
|
const input = {foo: 'string1', bar: 10};
|
|
3138
3138
|
await adapter.create('model', input);
|
|
3139
3139
|
await adapter.create('model', input);
|
|
@@ -3153,12 +3153,12 @@ describe('MemoryAdapter', function () {
|
|
|
3153
3153
|
});
|
|
3154
3154
|
|
|
3155
3155
|
it('allows to specify a full form of a fields clause to filter a return value', async function () {
|
|
3156
|
-
const
|
|
3157
|
-
|
|
3156
|
+
const dbs = new DatabaseSchema();
|
|
3157
|
+
dbs.defineDatasource({
|
|
3158
3158
|
name: 'memory',
|
|
3159
3159
|
adapter: 'memory',
|
|
3160
3160
|
});
|
|
3161
|
-
|
|
3161
|
+
dbs.defineModel({
|
|
3162
3162
|
name: 'model',
|
|
3163
3163
|
datasource: 'memory',
|
|
3164
3164
|
properties: {
|
|
@@ -3167,7 +3167,7 @@ describe('MemoryAdapter', function () {
|
|
|
3167
3167
|
baz: DataType.BOOLEAN,
|
|
3168
3168
|
},
|
|
3169
3169
|
});
|
|
3170
|
-
const adapter = new MemoryAdapter(
|
|
3170
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3171
3171
|
const input = {foo: 'string1', bar: 10, baz: true};
|
|
3172
3172
|
await adapter.create('model', input);
|
|
3173
3173
|
await adapter.create('model', input);
|
|
@@ -3199,12 +3199,12 @@ describe('MemoryAdapter', function () {
|
|
|
3199
3199
|
});
|
|
3200
3200
|
|
|
3201
3201
|
it('a fields clause uses property names instead of column names', async function () {
|
|
3202
|
-
const
|
|
3203
|
-
|
|
3202
|
+
const dbs = new DatabaseSchema();
|
|
3203
|
+
dbs.defineDatasource({
|
|
3204
3204
|
name: 'memory',
|
|
3205
3205
|
adapter: 'memory',
|
|
3206
3206
|
});
|
|
3207
|
-
|
|
3207
|
+
dbs.defineModel({
|
|
3208
3208
|
name: 'model',
|
|
3209
3209
|
datasource: 'memory',
|
|
3210
3210
|
properties: {
|
|
@@ -3222,7 +3222,7 @@ describe('MemoryAdapter', function () {
|
|
|
3222
3222
|
},
|
|
3223
3223
|
},
|
|
3224
3224
|
});
|
|
3225
|
-
const adapter = new MemoryAdapter(
|
|
3225
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3226
3226
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
3227
3227
|
await adapter.create('model', input);
|
|
3228
3228
|
await adapter.create('model', input);
|
|
@@ -3255,19 +3255,19 @@ describe('MemoryAdapter', function () {
|
|
|
3255
3255
|
});
|
|
3256
3256
|
|
|
3257
3257
|
it('allows to specify a short form of an order clause to sort a return value', async function () {
|
|
3258
|
-
const
|
|
3259
|
-
|
|
3258
|
+
const dbs = new DatabaseSchema();
|
|
3259
|
+
dbs.defineDatasource({
|
|
3260
3260
|
name: 'memory',
|
|
3261
3261
|
adapter: 'memory',
|
|
3262
3262
|
});
|
|
3263
|
-
|
|
3263
|
+
dbs.defineModel({
|
|
3264
3264
|
name: 'model',
|
|
3265
3265
|
datasource: 'memory',
|
|
3266
3266
|
properties: {
|
|
3267
3267
|
foo: DataType.NUMBER,
|
|
3268
3268
|
},
|
|
3269
3269
|
});
|
|
3270
|
-
const adapter = new MemoryAdapter(
|
|
3270
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3271
3271
|
await adapter.create('model', {foo: 20});
|
|
3272
3272
|
await adapter.create('model', {foo: 10});
|
|
3273
3273
|
await adapter.create('model', {foo: 15});
|
|
@@ -3289,12 +3289,12 @@ describe('MemoryAdapter', function () {
|
|
|
3289
3289
|
});
|
|
3290
3290
|
|
|
3291
3291
|
it('allows to specify a full form of an order clause to sort a return value', async function () {
|
|
3292
|
-
const
|
|
3293
|
-
|
|
3292
|
+
const dbs = new DatabaseSchema();
|
|
3293
|
+
dbs.defineDatasource({
|
|
3294
3294
|
name: 'memory',
|
|
3295
3295
|
adapter: 'memory',
|
|
3296
3296
|
});
|
|
3297
|
-
|
|
3297
|
+
dbs.defineModel({
|
|
3298
3298
|
name: 'model',
|
|
3299
3299
|
datasource: 'memory',
|
|
3300
3300
|
properties: {
|
|
@@ -3302,7 +3302,7 @@ describe('MemoryAdapter', function () {
|
|
|
3302
3302
|
bar: DataType.NUMBER,
|
|
3303
3303
|
},
|
|
3304
3304
|
});
|
|
3305
|
-
const adapter = new MemoryAdapter(
|
|
3305
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3306
3306
|
await adapter.create('model', {foo: 2, bar: 20});
|
|
3307
3307
|
await adapter.create('model', {foo: 2, bar: 10});
|
|
3308
3308
|
await adapter.create('model', {foo: 1, bar: 15});
|
|
@@ -3333,12 +3333,12 @@ describe('MemoryAdapter', function () {
|
|
|
3333
3333
|
});
|
|
3334
3334
|
|
|
3335
3335
|
it('an order clause uses property names instead of column names', async function () {
|
|
3336
|
-
const
|
|
3337
|
-
|
|
3336
|
+
const dbs = new DatabaseSchema();
|
|
3337
|
+
dbs.defineDatasource({
|
|
3338
3338
|
name: 'memory',
|
|
3339
3339
|
adapter: 'memory',
|
|
3340
3340
|
});
|
|
3341
|
-
|
|
3341
|
+
dbs.defineModel({
|
|
3342
3342
|
name: 'model',
|
|
3343
3343
|
datasource: 'memory',
|
|
3344
3344
|
properties: {
|
|
@@ -3352,7 +3352,7 @@ describe('MemoryAdapter', function () {
|
|
|
3352
3352
|
},
|
|
3353
3353
|
},
|
|
3354
3354
|
});
|
|
3355
|
-
const adapter = new MemoryAdapter(
|
|
3355
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3356
3356
|
const table = adapter._getTableOrCreate('model');
|
|
3357
3357
|
const tableInput1 = {fooCol: 2, barCol: 20};
|
|
3358
3358
|
const tableInput2 = {fooCol: 2, barCol: 10};
|
|
@@ -3387,12 +3387,12 @@ describe('MemoryAdapter', function () {
|
|
|
3387
3387
|
});
|
|
3388
3388
|
|
|
3389
3389
|
it('allows to specify the "where" clause to filter a return value', async function () {
|
|
3390
|
-
const
|
|
3391
|
-
|
|
3390
|
+
const dbs = new DatabaseSchema();
|
|
3391
|
+
dbs.defineDatasource({
|
|
3392
3392
|
name: 'memory',
|
|
3393
3393
|
adapter: 'memory',
|
|
3394
3394
|
});
|
|
3395
|
-
|
|
3395
|
+
dbs.defineModel({
|
|
3396
3396
|
name: 'model',
|
|
3397
3397
|
datasource: 'memory',
|
|
3398
3398
|
properties: {
|
|
@@ -3401,7 +3401,7 @@ describe('MemoryAdapter', function () {
|
|
|
3401
3401
|
baz: DataType.STRING,
|
|
3402
3402
|
},
|
|
3403
3403
|
});
|
|
3404
|
-
const adapter = new MemoryAdapter(
|
|
3404
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3405
3405
|
const input1 = {foo: 20, bar: true, baz: 'abc'};
|
|
3406
3406
|
const input2 = {foo: 10, bar: true, baz: 'abc'};
|
|
3407
3407
|
const input3 = {foo: 15, bar: false, baz: 'abe'};
|
|
@@ -3424,12 +3424,12 @@ describe('MemoryAdapter', function () {
|
|
|
3424
3424
|
});
|
|
3425
3425
|
|
|
3426
3426
|
it('the "where" clause uses property names instead of column names', async function () {
|
|
3427
|
-
const
|
|
3428
|
-
|
|
3427
|
+
const dbs = new DatabaseSchema();
|
|
3428
|
+
dbs.defineDatasource({
|
|
3429
3429
|
name: 'memory',
|
|
3430
3430
|
adapter: 'memory',
|
|
3431
3431
|
});
|
|
3432
|
-
|
|
3432
|
+
dbs.defineModel({
|
|
3433
3433
|
name: 'model',
|
|
3434
3434
|
datasource: 'memory',
|
|
3435
3435
|
properties: {
|
|
@@ -3447,7 +3447,7 @@ describe('MemoryAdapter', function () {
|
|
|
3447
3447
|
},
|
|
3448
3448
|
},
|
|
3449
3449
|
});
|
|
3450
|
-
const adapter = new MemoryAdapter(
|
|
3450
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3451
3451
|
const table = adapter._getTableOrCreate('model');
|
|
3452
3452
|
const tableInput1 = {fooCol: 20, barCol: true, bazCol: 'abc'};
|
|
3453
3453
|
const tableInput2 = {fooCol: 10, barCol: true, bazCol: 'abc'};
|
|
@@ -3481,12 +3481,12 @@ describe('MemoryAdapter', function () {
|
|
|
3481
3481
|
});
|
|
3482
3482
|
|
|
3483
3483
|
it('the "where" clause uses a persisted data instead of default values', async function () {
|
|
3484
|
-
const
|
|
3485
|
-
|
|
3484
|
+
const dbs = new DatabaseSchema();
|
|
3485
|
+
dbs.defineDatasource({
|
|
3486
3486
|
name: 'memory',
|
|
3487
3487
|
adapter: 'memory',
|
|
3488
3488
|
});
|
|
3489
|
-
|
|
3489
|
+
dbs.defineModel({
|
|
3490
3490
|
name: 'model',
|
|
3491
3491
|
datasource: 'memory',
|
|
3492
3492
|
properties: {
|
|
@@ -3496,7 +3496,7 @@ describe('MemoryAdapter', function () {
|
|
|
3496
3496
|
},
|
|
3497
3497
|
},
|
|
3498
3498
|
});
|
|
3499
|
-
const adapter = new MemoryAdapter(
|
|
3499
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3500
3500
|
const table = adapter._getTableOrCreate('model');
|
|
3501
3501
|
table.set(1, {[DEF_PK]: 1, foo: undefined});
|
|
3502
3502
|
table.set(2, {[DEF_PK]: 2, foo: undefined});
|
|
@@ -3514,19 +3514,19 @@ describe('MemoryAdapter', function () {
|
|
|
3514
3514
|
});
|
|
3515
3515
|
|
|
3516
3516
|
it('allows to specify a limit clause to filter a return value', async function () {
|
|
3517
|
-
const
|
|
3518
|
-
|
|
3517
|
+
const dbs = new DatabaseSchema();
|
|
3518
|
+
dbs.defineDatasource({
|
|
3519
3519
|
name: 'memory',
|
|
3520
3520
|
adapter: 'memory',
|
|
3521
3521
|
});
|
|
3522
|
-
|
|
3522
|
+
dbs.defineModel({
|
|
3523
3523
|
name: 'model',
|
|
3524
3524
|
datasource: 'memory',
|
|
3525
3525
|
properties: {
|
|
3526
3526
|
foo: DataType.NUMBER,
|
|
3527
3527
|
},
|
|
3528
3528
|
});
|
|
3529
|
-
const adapter = new MemoryAdapter(
|
|
3529
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3530
3530
|
await adapter.create('model', {});
|
|
3531
3531
|
await adapter.create('model', {});
|
|
3532
3532
|
await adapter.create('model', {});
|
|
@@ -3545,19 +3545,19 @@ describe('MemoryAdapter', function () {
|
|
|
3545
3545
|
});
|
|
3546
3546
|
|
|
3547
3547
|
it('allows to specify a skip clause to filter a return value', async function () {
|
|
3548
|
-
const
|
|
3549
|
-
|
|
3548
|
+
const dbs = new DatabaseSchema();
|
|
3549
|
+
dbs.defineDatasource({
|
|
3550
3550
|
name: 'memory',
|
|
3551
3551
|
adapter: 'memory',
|
|
3552
3552
|
});
|
|
3553
|
-
|
|
3553
|
+
dbs.defineModel({
|
|
3554
3554
|
name: 'model',
|
|
3555
3555
|
datasource: 'memory',
|
|
3556
3556
|
properties: {
|
|
3557
3557
|
foo: DataType.NUMBER,
|
|
3558
3558
|
},
|
|
3559
3559
|
});
|
|
3560
|
-
const adapter = new MemoryAdapter(
|
|
3560
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3561
3561
|
await adapter.create('model', {});
|
|
3562
3562
|
await adapter.create('model', {});
|
|
3563
3563
|
await adapter.create('model', {});
|
|
@@ -3578,16 +3578,16 @@ describe('MemoryAdapter', function () {
|
|
|
3578
3578
|
|
|
3579
3579
|
describe('findById', function () {
|
|
3580
3580
|
it('throws an error if a given identifier does not exist', async function () {
|
|
3581
|
-
const
|
|
3582
|
-
|
|
3581
|
+
const dbs = new DatabaseSchema();
|
|
3582
|
+
dbs.defineDatasource({
|
|
3583
3583
|
name: 'memory',
|
|
3584
3584
|
adapter: 'memory',
|
|
3585
3585
|
});
|
|
3586
|
-
|
|
3586
|
+
dbs.defineModel({
|
|
3587
3587
|
name: 'model',
|
|
3588
3588
|
datasource: 'memory',
|
|
3589
3589
|
});
|
|
3590
|
-
const adapter = new MemoryAdapter(
|
|
3590
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3591
3591
|
const promise = adapter.findById('model', 1);
|
|
3592
3592
|
await expect(promise).to.be.rejectedWith(
|
|
3593
3593
|
format(
|
|
@@ -3598,12 +3598,12 @@ describe('MemoryAdapter', function () {
|
|
|
3598
3598
|
});
|
|
3599
3599
|
|
|
3600
3600
|
it('uses default values for non-existent properties', async function () {
|
|
3601
|
-
const
|
|
3602
|
-
|
|
3601
|
+
const dbs = new DatabaseSchema();
|
|
3602
|
+
dbs.defineDatasource({
|
|
3603
3603
|
name: 'memory',
|
|
3604
3604
|
adapter: 'memory',
|
|
3605
3605
|
});
|
|
3606
|
-
|
|
3606
|
+
dbs.defineModel({
|
|
3607
3607
|
name: 'model',
|
|
3608
3608
|
datasource: 'memory',
|
|
3609
3609
|
properties: {
|
|
@@ -3613,7 +3613,7 @@ describe('MemoryAdapter', function () {
|
|
|
3613
3613
|
},
|
|
3614
3614
|
},
|
|
3615
3615
|
});
|
|
3616
|
-
const adapter = new MemoryAdapter(
|
|
3616
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3617
3617
|
const table = adapter._getTableOrCreate('model');
|
|
3618
3618
|
const idValue = 1;
|
|
3619
3619
|
table.set(idValue, {[DEF_PK]: idValue});
|
|
@@ -3624,12 +3624,12 @@ describe('MemoryAdapter', function () {
|
|
|
3624
3624
|
});
|
|
3625
3625
|
|
|
3626
3626
|
it('uses default values for properties of an undefined', async function () {
|
|
3627
|
-
const
|
|
3628
|
-
|
|
3627
|
+
const dbs = new DatabaseSchema();
|
|
3628
|
+
dbs.defineDatasource({
|
|
3629
3629
|
name: 'memory',
|
|
3630
3630
|
adapter: 'memory',
|
|
3631
3631
|
});
|
|
3632
|
-
|
|
3632
|
+
dbs.defineModel({
|
|
3633
3633
|
name: 'model',
|
|
3634
3634
|
datasource: 'memory',
|
|
3635
3635
|
properties: {
|
|
@@ -3639,7 +3639,7 @@ describe('MemoryAdapter', function () {
|
|
|
3639
3639
|
},
|
|
3640
3640
|
},
|
|
3641
3641
|
});
|
|
3642
|
-
const adapter = new MemoryAdapter(
|
|
3642
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3643
3643
|
const table = adapter._getTableOrCreate('model');
|
|
3644
3644
|
const idValue = 1;
|
|
3645
3645
|
const input = {foo: undefined};
|
|
@@ -3651,12 +3651,12 @@ describe('MemoryAdapter', function () {
|
|
|
3651
3651
|
});
|
|
3652
3652
|
|
|
3653
3653
|
it('uses default values for properties of a null', async function () {
|
|
3654
|
-
const
|
|
3655
|
-
|
|
3654
|
+
const dbs = new DatabaseSchema();
|
|
3655
|
+
dbs.defineDatasource({
|
|
3656
3656
|
name: 'memory',
|
|
3657
3657
|
adapter: 'memory',
|
|
3658
3658
|
});
|
|
3659
|
-
|
|
3659
|
+
dbs.defineModel({
|
|
3660
3660
|
name: 'model',
|
|
3661
3661
|
datasource: 'memory',
|
|
3662
3662
|
properties: {
|
|
@@ -3666,7 +3666,7 @@ describe('MemoryAdapter', function () {
|
|
|
3666
3666
|
},
|
|
3667
3667
|
},
|
|
3668
3668
|
});
|
|
3669
|
-
const adapter = new MemoryAdapter(
|
|
3669
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3670
3670
|
const table = adapter._getTableOrCreate('model');
|
|
3671
3671
|
const idValue = 1;
|
|
3672
3672
|
const input = {foo: null};
|
|
@@ -3678,12 +3678,12 @@ describe('MemoryAdapter', function () {
|
|
|
3678
3678
|
});
|
|
3679
3679
|
|
|
3680
3680
|
it('uses a specified column name for a primary key', async function () {
|
|
3681
|
-
const
|
|
3682
|
-
|
|
3681
|
+
const dbs = new DatabaseSchema();
|
|
3682
|
+
dbs.defineDatasource({
|
|
3683
3683
|
name: 'memory',
|
|
3684
3684
|
adapter: 'memory',
|
|
3685
3685
|
});
|
|
3686
|
-
|
|
3686
|
+
dbs.defineModel({
|
|
3687
3687
|
name: 'model',
|
|
3688
3688
|
datasource: 'memory',
|
|
3689
3689
|
properties: {
|
|
@@ -3696,7 +3696,7 @@ describe('MemoryAdapter', function () {
|
|
|
3696
3696
|
baz: DataType.NUMBER,
|
|
3697
3697
|
},
|
|
3698
3698
|
});
|
|
3699
|
-
const adapter = new MemoryAdapter(
|
|
3699
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3700
3700
|
const input = {bar: 1, baz: 2};
|
|
3701
3701
|
const table = adapter._getTableOrCreate('model');
|
|
3702
3702
|
const idValue = 1;
|
|
@@ -3706,12 +3706,12 @@ describe('MemoryAdapter', function () {
|
|
|
3706
3706
|
});
|
|
3707
3707
|
|
|
3708
3708
|
it('uses a specified column name for a regular property', async function () {
|
|
3709
|
-
const
|
|
3710
|
-
|
|
3709
|
+
const dbs = new DatabaseSchema();
|
|
3710
|
+
dbs.defineDatasource({
|
|
3711
3711
|
name: 'memory',
|
|
3712
3712
|
adapter: 'memory',
|
|
3713
3713
|
});
|
|
3714
|
-
|
|
3714
|
+
dbs.defineModel({
|
|
3715
3715
|
name: 'model',
|
|
3716
3716
|
datasource: 'memory',
|
|
3717
3717
|
properties: {
|
|
@@ -3722,7 +3722,7 @@ describe('MemoryAdapter', function () {
|
|
|
3722
3722
|
bar: DataType.NUMBER,
|
|
3723
3723
|
},
|
|
3724
3724
|
});
|
|
3725
|
-
const adapter = new MemoryAdapter(
|
|
3725
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3726
3726
|
const table = adapter._getTableOrCreate('model');
|
|
3727
3727
|
const idValue = 1;
|
|
3728
3728
|
const input = {foo: 1, bar: 2};
|
|
@@ -3736,12 +3736,12 @@ describe('MemoryAdapter', function () {
|
|
|
3736
3736
|
});
|
|
3737
3737
|
|
|
3738
3738
|
it('uses a specified column name for a regular property with a default value', async function () {
|
|
3739
|
-
const
|
|
3740
|
-
|
|
3739
|
+
const dbs = new DatabaseSchema();
|
|
3740
|
+
dbs.defineDatasource({
|
|
3741
3741
|
name: 'memory',
|
|
3742
3742
|
adapter: 'memory',
|
|
3743
3743
|
});
|
|
3744
|
-
|
|
3744
|
+
dbs.defineModel({
|
|
3745
3745
|
name: 'model',
|
|
3746
3746
|
datasource: 'memory',
|
|
3747
3747
|
properties: {
|
|
@@ -3756,7 +3756,7 @@ describe('MemoryAdapter', function () {
|
|
|
3756
3756
|
},
|
|
3757
3757
|
},
|
|
3758
3758
|
});
|
|
3759
|
-
const adapter = new MemoryAdapter(
|
|
3759
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3760
3760
|
const table = adapter._getTableOrCreate('model');
|
|
3761
3761
|
const idValue = 1;
|
|
3762
3762
|
table.set(idValue, {[DEF_PK]: idValue});
|
|
@@ -3766,12 +3766,12 @@ describe('MemoryAdapter', function () {
|
|
|
3766
3766
|
});
|
|
3767
3767
|
|
|
3768
3768
|
it('allows to specify a short form of a fields clause to filter a return value', async function () {
|
|
3769
|
-
const
|
|
3770
|
-
|
|
3769
|
+
const dbs = new DatabaseSchema();
|
|
3770
|
+
dbs.defineDatasource({
|
|
3771
3771
|
name: 'memory',
|
|
3772
3772
|
adapter: 'memory',
|
|
3773
3773
|
});
|
|
3774
|
-
|
|
3774
|
+
dbs.defineModel({
|
|
3775
3775
|
name: 'model',
|
|
3776
3776
|
datasource: 'memory',
|
|
3777
3777
|
properties: {
|
|
@@ -3779,7 +3779,7 @@ describe('MemoryAdapter', function () {
|
|
|
3779
3779
|
bar: DataType.NUMBER,
|
|
3780
3780
|
},
|
|
3781
3781
|
});
|
|
3782
|
-
const adapter = new MemoryAdapter(
|
|
3782
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3783
3783
|
const table = adapter._getTableOrCreate('model');
|
|
3784
3784
|
const input = {foo: 'string', bar: 10};
|
|
3785
3785
|
const idValue = 1;
|
|
@@ -3789,12 +3789,12 @@ describe('MemoryAdapter', function () {
|
|
|
3789
3789
|
});
|
|
3790
3790
|
|
|
3791
3791
|
it('allows to specify a full form of a fields clause to filter a return value', async function () {
|
|
3792
|
-
const
|
|
3793
|
-
|
|
3792
|
+
const dbs = new DatabaseSchema();
|
|
3793
|
+
dbs.defineDatasource({
|
|
3794
3794
|
name: 'memory',
|
|
3795
3795
|
adapter: 'memory',
|
|
3796
3796
|
});
|
|
3797
|
-
|
|
3797
|
+
dbs.defineModel({
|
|
3798
3798
|
name: 'model',
|
|
3799
3799
|
datasource: 'memory',
|
|
3800
3800
|
properties: {
|
|
@@ -3803,7 +3803,7 @@ describe('MemoryAdapter', function () {
|
|
|
3803
3803
|
baz: DataType.BOOLEAN,
|
|
3804
3804
|
},
|
|
3805
3805
|
});
|
|
3806
|
-
const adapter = new MemoryAdapter(
|
|
3806
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3807
3807
|
const table = adapter._getTableOrCreate('model');
|
|
3808
3808
|
const input = {foo: 'string', bar: 10, baz: true};
|
|
3809
3809
|
const idValue = 1;
|
|
@@ -3818,12 +3818,12 @@ describe('MemoryAdapter', function () {
|
|
|
3818
3818
|
});
|
|
3819
3819
|
|
|
3820
3820
|
it('a fields clause uses property names instead of column names', async function () {
|
|
3821
|
-
const
|
|
3822
|
-
|
|
3821
|
+
const dbs = new DatabaseSchema();
|
|
3822
|
+
dbs.defineDatasource({
|
|
3823
3823
|
name: 'memory',
|
|
3824
3824
|
adapter: 'memory',
|
|
3825
3825
|
});
|
|
3826
|
-
|
|
3826
|
+
dbs.defineModel({
|
|
3827
3827
|
name: 'model',
|
|
3828
3828
|
datasource: 'memory',
|
|
3829
3829
|
properties: {
|
|
@@ -3841,7 +3841,7 @@ describe('MemoryAdapter', function () {
|
|
|
3841
3841
|
},
|
|
3842
3842
|
},
|
|
3843
3843
|
});
|
|
3844
|
-
const adapter = new MemoryAdapter(
|
|
3844
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3845
3845
|
const table = adapter._getTableOrCreate('model');
|
|
3846
3846
|
const tableInput = {fooCol: 'string', barCol: 10, bazCol: true};
|
|
3847
3847
|
const idValue = 1;
|
|
@@ -3861,16 +3861,16 @@ describe('MemoryAdapter', function () {
|
|
|
3861
3861
|
|
|
3862
3862
|
describe('delete', function () {
|
|
3863
3863
|
it('removes all table items and returns their number', async function () {
|
|
3864
|
-
const
|
|
3865
|
-
|
|
3864
|
+
const dbs = new DatabaseSchema();
|
|
3865
|
+
dbs.defineDatasource({
|
|
3866
3866
|
name: 'memory',
|
|
3867
3867
|
adapter: 'memory',
|
|
3868
3868
|
});
|
|
3869
|
-
|
|
3869
|
+
dbs.defineModel({
|
|
3870
3870
|
name: 'model',
|
|
3871
3871
|
datasource: 'memory',
|
|
3872
3872
|
});
|
|
3873
|
-
const adapter = new MemoryAdapter(
|
|
3873
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3874
3874
|
const table = adapter._getTableOrCreate('model');
|
|
3875
3875
|
table.set(1, {[DEF_PK]: 1});
|
|
3876
3876
|
table.set(2, {[DEF_PK]: 2});
|
|
@@ -3882,34 +3882,34 @@ describe('MemoryAdapter', function () {
|
|
|
3882
3882
|
});
|
|
3883
3883
|
|
|
3884
3884
|
it('returns zero if nothing to remove', async function () {
|
|
3885
|
-
const
|
|
3886
|
-
|
|
3885
|
+
const dbs = new DatabaseSchema();
|
|
3886
|
+
dbs.defineDatasource({
|
|
3887
3887
|
name: 'memory',
|
|
3888
3888
|
adapter: 'memory',
|
|
3889
3889
|
});
|
|
3890
|
-
|
|
3890
|
+
dbs.defineModel({
|
|
3891
3891
|
name: 'model',
|
|
3892
3892
|
datasource: 'memory',
|
|
3893
3893
|
});
|
|
3894
|
-
const adapter = new MemoryAdapter(
|
|
3894
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3895
3895
|
const result = await adapter.delete('model');
|
|
3896
3896
|
expect(result).to.be.eq(0);
|
|
3897
3897
|
});
|
|
3898
3898
|
|
|
3899
3899
|
it('uses a given where clause to remove specific items', async function () {
|
|
3900
|
-
const
|
|
3901
|
-
|
|
3900
|
+
const dbs = new DatabaseSchema();
|
|
3901
|
+
dbs.defineDatasource({
|
|
3902
3902
|
name: 'memory',
|
|
3903
3903
|
adapter: 'memory',
|
|
3904
3904
|
});
|
|
3905
|
-
|
|
3905
|
+
dbs.defineModel({
|
|
3906
3906
|
name: 'model',
|
|
3907
3907
|
datasource: 'memory',
|
|
3908
3908
|
properties: {
|
|
3909
3909
|
foo: DataType.NUMBER,
|
|
3910
3910
|
},
|
|
3911
3911
|
});
|
|
3912
|
-
const adapter = new MemoryAdapter(
|
|
3912
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3913
3913
|
await adapter.create('model', {foo: 20});
|
|
3914
3914
|
await adapter.create('model', {foo: 10});
|
|
3915
3915
|
await adapter.create('model', {foo: 15});
|
|
@@ -3922,12 +3922,12 @@ describe('MemoryAdapter', function () {
|
|
|
3922
3922
|
});
|
|
3923
3923
|
|
|
3924
3924
|
it('the "where" clause uses property names instead of column names', async function () {
|
|
3925
|
-
const
|
|
3926
|
-
|
|
3925
|
+
const dbs = new DatabaseSchema();
|
|
3926
|
+
dbs.defineDatasource({
|
|
3927
3927
|
name: 'memory',
|
|
3928
3928
|
adapter: 'memory',
|
|
3929
3929
|
});
|
|
3930
|
-
|
|
3930
|
+
dbs.defineModel({
|
|
3931
3931
|
name: 'model',
|
|
3932
3932
|
datasource: 'memory',
|
|
3933
3933
|
properties: {
|
|
@@ -3937,7 +3937,7 @@ describe('MemoryAdapter', function () {
|
|
|
3937
3937
|
},
|
|
3938
3938
|
},
|
|
3939
3939
|
});
|
|
3940
|
-
const adapter = new MemoryAdapter(
|
|
3940
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3941
3941
|
const table = adapter._getTableOrCreate('model');
|
|
3942
3942
|
table.set(1, {[DEF_PK]: 1, fooCol: 20});
|
|
3943
3943
|
table.set(2, {[DEF_PK]: 2, fooCol: 10});
|
|
@@ -3949,12 +3949,12 @@ describe('MemoryAdapter', function () {
|
|
|
3949
3949
|
});
|
|
3950
3950
|
|
|
3951
3951
|
it('the "where" clause uses a persisted data instead of default values', async function () {
|
|
3952
|
-
const
|
|
3953
|
-
|
|
3952
|
+
const dbs = new DatabaseSchema();
|
|
3953
|
+
dbs.defineDatasource({
|
|
3954
3954
|
name: 'memory',
|
|
3955
3955
|
adapter: 'memory',
|
|
3956
3956
|
});
|
|
3957
|
-
|
|
3957
|
+
dbs.defineModel({
|
|
3958
3958
|
name: 'model',
|
|
3959
3959
|
datasource: 'memory',
|
|
3960
3960
|
properties: {
|
|
@@ -3964,7 +3964,7 @@ describe('MemoryAdapter', function () {
|
|
|
3964
3964
|
},
|
|
3965
3965
|
},
|
|
3966
3966
|
});
|
|
3967
|
-
const adapter = new MemoryAdapter(
|
|
3967
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
3968
3968
|
const table = adapter._getTableOrCreate('model');
|
|
3969
3969
|
const input1 = {[DEF_PK]: 1, foo: undefined};
|
|
3970
3970
|
const input2 = {[DEF_PK]: 2, foo: undefined};
|
|
@@ -3993,31 +3993,31 @@ describe('MemoryAdapter', function () {
|
|
|
3993
3993
|
|
|
3994
3994
|
describe('deleteById', function () {
|
|
3995
3995
|
it('returns false if a given identifier is not exist', async function () {
|
|
3996
|
-
const
|
|
3997
|
-
|
|
3996
|
+
const dbs = new DatabaseSchema();
|
|
3997
|
+
dbs.defineDatasource({
|
|
3998
3998
|
name: 'memory',
|
|
3999
3999
|
adapter: 'memory',
|
|
4000
4000
|
});
|
|
4001
|
-
|
|
4001
|
+
dbs.defineModel({
|
|
4002
4002
|
name: 'model',
|
|
4003
4003
|
datasource: 'memory',
|
|
4004
4004
|
});
|
|
4005
|
-
const adapter = new MemoryAdapter(
|
|
4005
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4006
4006
|
const result = await adapter.deleteById('model', 1);
|
|
4007
4007
|
expect(result).to.be.false;
|
|
4008
4008
|
});
|
|
4009
4009
|
|
|
4010
4010
|
it('returns true if an item has removed by a given identifier', async function () {
|
|
4011
|
-
const
|
|
4012
|
-
|
|
4011
|
+
const dbs = new DatabaseSchema();
|
|
4012
|
+
dbs.defineDatasource({
|
|
4013
4013
|
name: 'memory',
|
|
4014
4014
|
adapter: 'memory',
|
|
4015
4015
|
});
|
|
4016
|
-
|
|
4016
|
+
dbs.defineModel({
|
|
4017
4017
|
name: 'model',
|
|
4018
4018
|
datasource: 'memory',
|
|
4019
4019
|
});
|
|
4020
|
-
const adapter = new MemoryAdapter(
|
|
4020
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4021
4021
|
const created = await adapter.create('model', {});
|
|
4022
4022
|
const idValue = created[DEF_PK];
|
|
4023
4023
|
const result = await adapter.deleteById('model', idValue);
|
|
@@ -4025,12 +4025,12 @@ describe('MemoryAdapter', function () {
|
|
|
4025
4025
|
});
|
|
4026
4026
|
|
|
4027
4027
|
it('uses a specified column name for a primary key', async function () {
|
|
4028
|
-
const
|
|
4029
|
-
|
|
4028
|
+
const dbs = new DatabaseSchema();
|
|
4029
|
+
dbs.defineDatasource({
|
|
4030
4030
|
name: 'memory',
|
|
4031
4031
|
adapter: 'memory',
|
|
4032
4032
|
});
|
|
4033
|
-
|
|
4033
|
+
dbs.defineModel({
|
|
4034
4034
|
name: 'model',
|
|
4035
4035
|
datasource: 'memory',
|
|
4036
4036
|
properties: {
|
|
@@ -4042,7 +4042,7 @@ describe('MemoryAdapter', function () {
|
|
|
4042
4042
|
bar: DataType.NUMBER,
|
|
4043
4043
|
},
|
|
4044
4044
|
});
|
|
4045
|
-
const adapter = new MemoryAdapter(
|
|
4045
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4046
4046
|
const table = adapter._getTableOrCreate('model');
|
|
4047
4047
|
const idValue = 1;
|
|
4048
4048
|
table.set(idValue, {qux: idValue, bar: 10});
|
|
@@ -4055,43 +4055,43 @@ describe('MemoryAdapter', function () {
|
|
|
4055
4055
|
|
|
4056
4056
|
describe('exists', function () {
|
|
4057
4057
|
it('returns false if a given identifier is not exist', async function () {
|
|
4058
|
-
const
|
|
4059
|
-
|
|
4058
|
+
const dbs = new DatabaseSchema();
|
|
4059
|
+
dbs.defineDatasource({
|
|
4060
4060
|
name: 'memory',
|
|
4061
4061
|
adapter: 'memory',
|
|
4062
4062
|
});
|
|
4063
|
-
|
|
4063
|
+
dbs.defineModel({
|
|
4064
4064
|
name: 'model',
|
|
4065
4065
|
datasource: 'memory',
|
|
4066
4066
|
});
|
|
4067
|
-
const adapter = new MemoryAdapter(
|
|
4067
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4068
4068
|
const result = await adapter.exists('model', 1);
|
|
4069
4069
|
expect(result).to.be.false;
|
|
4070
4070
|
});
|
|
4071
4071
|
|
|
4072
4072
|
it('returns true if a given identifier is exist', async function () {
|
|
4073
|
-
const
|
|
4074
|
-
|
|
4073
|
+
const dbs = new DatabaseSchema();
|
|
4074
|
+
dbs.defineDatasource({
|
|
4075
4075
|
name: 'memory',
|
|
4076
4076
|
adapter: 'memory',
|
|
4077
4077
|
});
|
|
4078
|
-
|
|
4078
|
+
dbs.defineModel({
|
|
4079
4079
|
name: 'model',
|
|
4080
4080
|
datasource: 'memory',
|
|
4081
4081
|
});
|
|
4082
|
-
const adapter = new MemoryAdapter(
|
|
4082
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4083
4083
|
await adapter.create('model', {});
|
|
4084
4084
|
const result = await adapter.exists('model', 1);
|
|
4085
4085
|
expect(result).to.be.true;
|
|
4086
4086
|
});
|
|
4087
4087
|
|
|
4088
4088
|
it('uses a specified column name for a primary key', async function () {
|
|
4089
|
-
const
|
|
4090
|
-
|
|
4089
|
+
const dbs = new DatabaseSchema();
|
|
4090
|
+
dbs.defineDatasource({
|
|
4091
4091
|
name: 'memory',
|
|
4092
4092
|
adapter: 'memory',
|
|
4093
4093
|
});
|
|
4094
|
-
|
|
4094
|
+
dbs.defineModel({
|
|
4095
4095
|
name: 'model',
|
|
4096
4096
|
datasource: 'memory',
|
|
4097
4097
|
properties: {
|
|
@@ -4102,7 +4102,7 @@ describe('MemoryAdapter', function () {
|
|
|
4102
4102
|
},
|
|
4103
4103
|
},
|
|
4104
4104
|
});
|
|
4105
|
-
const adapter = new MemoryAdapter(
|
|
4105
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4106
4106
|
const table = adapter._getTableOrCreate('model');
|
|
4107
4107
|
const idValue = 1;
|
|
4108
4108
|
table.set(idValue, {qux: idValue});
|
|
@@ -4113,34 +4113,34 @@ describe('MemoryAdapter', function () {
|
|
|
4113
4113
|
|
|
4114
4114
|
describe('count', function () {
|
|
4115
4115
|
it('returns zero if nothing to count', async function () {
|
|
4116
|
-
const
|
|
4117
|
-
|
|
4116
|
+
const dbs = new DatabaseSchema();
|
|
4117
|
+
dbs.defineDatasource({
|
|
4118
4118
|
name: 'memory',
|
|
4119
4119
|
adapter: 'memory',
|
|
4120
4120
|
});
|
|
4121
|
-
|
|
4121
|
+
dbs.defineModel({
|
|
4122
4122
|
name: 'model',
|
|
4123
4123
|
datasource: 'memory',
|
|
4124
4124
|
});
|
|
4125
|
-
const adapter = new MemoryAdapter(
|
|
4125
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4126
4126
|
const result = await adapter.count('model');
|
|
4127
4127
|
expect(result).to.be.eq(0);
|
|
4128
4128
|
});
|
|
4129
4129
|
|
|
4130
4130
|
it('returns zero if a given where clause does not met', async function () {
|
|
4131
|
-
const
|
|
4132
|
-
|
|
4131
|
+
const dbs = new DatabaseSchema();
|
|
4132
|
+
dbs.defineDatasource({
|
|
4133
4133
|
name: 'memory',
|
|
4134
4134
|
adapter: 'memory',
|
|
4135
4135
|
});
|
|
4136
|
-
|
|
4136
|
+
dbs.defineModel({
|
|
4137
4137
|
name: 'model',
|
|
4138
4138
|
datasource: 'memory',
|
|
4139
4139
|
properties: {
|
|
4140
4140
|
foo: DataType.NUMBER,
|
|
4141
4141
|
},
|
|
4142
4142
|
});
|
|
4143
|
-
const adapter = new MemoryAdapter(
|
|
4143
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4144
4144
|
await adapter.create('model', {foo: 20});
|
|
4145
4145
|
await adapter.create('model', {foo: 10});
|
|
4146
4146
|
await adapter.create('model', {foo: 15});
|
|
@@ -4155,16 +4155,16 @@ describe('MemoryAdapter', function () {
|
|
|
4155
4155
|
});
|
|
4156
4156
|
|
|
4157
4157
|
it('returns a number of table items', async function () {
|
|
4158
|
-
const
|
|
4159
|
-
|
|
4158
|
+
const dbs = new DatabaseSchema();
|
|
4159
|
+
dbs.defineDatasource({
|
|
4160
4160
|
name: 'memory',
|
|
4161
4161
|
adapter: 'memory',
|
|
4162
4162
|
});
|
|
4163
|
-
|
|
4163
|
+
dbs.defineModel({
|
|
4164
4164
|
name: 'model',
|
|
4165
4165
|
datasource: 'memory',
|
|
4166
4166
|
});
|
|
4167
|
-
const adapter = new MemoryAdapter(
|
|
4167
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4168
4168
|
await adapter.create('model', {});
|
|
4169
4169
|
await adapter.create('model', {});
|
|
4170
4170
|
await adapter.create('model', {});
|
|
@@ -4173,19 +4173,19 @@ describe('MemoryAdapter', function () {
|
|
|
4173
4173
|
});
|
|
4174
4174
|
|
|
4175
4175
|
it('uses a given where clause to count specific items', async function () {
|
|
4176
|
-
const
|
|
4177
|
-
|
|
4176
|
+
const dbs = new DatabaseSchema();
|
|
4177
|
+
dbs.defineDatasource({
|
|
4178
4178
|
name: 'memory',
|
|
4179
4179
|
adapter: 'memory',
|
|
4180
4180
|
});
|
|
4181
|
-
|
|
4181
|
+
dbs.defineModel({
|
|
4182
4182
|
name: 'model',
|
|
4183
4183
|
datasource: 'memory',
|
|
4184
4184
|
properties: {
|
|
4185
4185
|
foo: DataType.NUMBER,
|
|
4186
4186
|
},
|
|
4187
4187
|
});
|
|
4188
|
-
const adapter = new MemoryAdapter(
|
|
4188
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4189
4189
|
await adapter.create('model', {foo: 20});
|
|
4190
4190
|
await adapter.create('model', {foo: 10});
|
|
4191
4191
|
await adapter.create('model', {foo: 15});
|
|
@@ -4200,12 +4200,12 @@ describe('MemoryAdapter', function () {
|
|
|
4200
4200
|
});
|
|
4201
4201
|
|
|
4202
4202
|
it('the "where" clause uses property names instead of column names', async function () {
|
|
4203
|
-
const
|
|
4204
|
-
|
|
4203
|
+
const dbs = new DatabaseSchema();
|
|
4204
|
+
dbs.defineDatasource({
|
|
4205
4205
|
name: 'memory',
|
|
4206
4206
|
adapter: 'memory',
|
|
4207
4207
|
});
|
|
4208
|
-
|
|
4208
|
+
dbs.defineModel({
|
|
4209
4209
|
name: 'model',
|
|
4210
4210
|
datasource: 'memory',
|
|
4211
4211
|
properties: {
|
|
@@ -4215,7 +4215,7 @@ describe('MemoryAdapter', function () {
|
|
|
4215
4215
|
},
|
|
4216
4216
|
},
|
|
4217
4217
|
});
|
|
4218
|
-
const adapter = new MemoryAdapter(
|
|
4218
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4219
4219
|
const table = adapter._getTableOrCreate('model');
|
|
4220
4220
|
table.set(1, {[DEF_PK]: 1, fooCol: 20});
|
|
4221
4221
|
table.set(2, {[DEF_PK]: 2, fooCol: 10});
|
|
@@ -4230,12 +4230,12 @@ describe('MemoryAdapter', function () {
|
|
|
4230
4230
|
});
|
|
4231
4231
|
|
|
4232
4232
|
it('the "where" clause uses a persisted data instead of default values', async function () {
|
|
4233
|
-
const
|
|
4234
|
-
|
|
4233
|
+
const dbs = new DatabaseSchema();
|
|
4234
|
+
dbs.defineDatasource({
|
|
4235
4235
|
name: 'memory',
|
|
4236
4236
|
adapter: 'memory',
|
|
4237
4237
|
});
|
|
4238
|
-
|
|
4238
|
+
dbs.defineModel({
|
|
4239
4239
|
name: 'model',
|
|
4240
4240
|
datasource: 'memory',
|
|
4241
4241
|
properties: {
|
|
@@ -4245,7 +4245,7 @@ describe('MemoryAdapter', function () {
|
|
|
4245
4245
|
},
|
|
4246
4246
|
},
|
|
4247
4247
|
});
|
|
4248
|
-
const adapter = new MemoryAdapter(
|
|
4248
|
+
const adapter = new MemoryAdapter(dbs.container, {});
|
|
4249
4249
|
const table = adapter._getTableOrCreate('model');
|
|
4250
4250
|
table.set(1, {[DEF_PK]: 1, foo: undefined});
|
|
4251
4251
|
table.set(2, {[DEF_PK]: 2, foo: undefined});
|