@expo/entity-database-adapter-knex 0.63.0 → 0.64.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 +1 -1
- package/build/src/AuthorizationResultBasedKnexEntityLoader.d.ts +18 -0
- package/build/src/AuthorizationResultBasedKnexEntityLoader.js +28 -0
- package/build/src/BasePostgresEntityDatabaseAdapter.d.ts +19 -0
- package/build/src/BasePostgresEntityDatabaseAdapter.js +37 -0
- package/build/src/BaseSQLQueryBuilder.d.ts +2 -2
- package/build/src/BaseSQLQueryBuilder.js +2 -2
- package/build/src/EnforcingKnexEntityLoader.d.ts +18 -0
- package/build/src/EnforcingKnexEntityLoader.js +22 -0
- package/build/src/PostgresEntityDatabaseAdapter.d.ts +4 -0
- package/build/src/PostgresEntityDatabaseAdapter.js +24 -10
- package/build/src/SQLOperator.d.ts +15 -14
- package/build/src/SQLOperator.js +11 -8
- package/build/src/internal/EntityKnexDataManager.d.ts +2 -0
- package/build/src/internal/EntityKnexDataManager.js +13 -10
- package/package.json +16 -16
- package/src/AuthorizationResultBasedKnexEntityLoader.ts +36 -0
- package/src/BasePostgresEntityDatabaseAdapter.ts +67 -0
- package/src/BaseSQLQueryBuilder.ts +2 -2
- package/src/EnforcingKnexEntityLoader.ts +26 -0
- package/src/PostgresEntityDatabaseAdapter.ts +68 -20
- package/src/SQLOperator.ts +23 -22
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +97 -0
- package/src/__tests__/BasePostgresEntityDatabaseAdapter-test.ts +17 -0
- package/src/__tests__/SQLOperator-test.ts +2 -29
- package/src/__tests__/fixtures/StubPostgresDatabaseAdapter.ts +25 -1
- package/src/internal/EntityKnexDataManager.ts +38 -9
|
@@ -76,7 +76,7 @@ export class StubPostgresDatabaseAdapter<
|
|
|
76
76
|
): Promise<object[]> {
|
|
77
77
|
const objectCollection = this.getObjectCollectionForTable(tableName);
|
|
78
78
|
const results = StubPostgresDatabaseAdapter.uniqBy(tableTuples, (tuple) =>
|
|
79
|
-
|
|
79
|
+
JSON.stringify(tuple),
|
|
80
80
|
).reduce(
|
|
81
81
|
(acc, tableTuple) => {
|
|
82
82
|
return acc.concat(
|
|
@@ -202,6 +202,30 @@ export class StubPostgresDatabaseAdapter<
|
|
|
202
202
|
throw new Error('SQL fragments not supported for StubDatabaseAdapter');
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
protected async countByFieldEqualityConjunctionInternalAsync(
|
|
206
|
+
queryInterface: any,
|
|
207
|
+
tableName: string,
|
|
208
|
+
tableFieldSingleValueEqualityOperands: TableFieldSingleValueEqualityCondition[],
|
|
209
|
+
tableFieldMultiValueEqualityOperands: TableFieldMultiValueEqualityCondition[],
|
|
210
|
+
): Promise<number> {
|
|
211
|
+
const results = await this.fetchManyByFieldEqualityConjunctionInternalAsync(
|
|
212
|
+
queryInterface,
|
|
213
|
+
tableName,
|
|
214
|
+
tableFieldSingleValueEqualityOperands,
|
|
215
|
+
tableFieldMultiValueEqualityOperands,
|
|
216
|
+
{ orderBy: undefined, offset: undefined, limit: undefined },
|
|
217
|
+
);
|
|
218
|
+
return results.length;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
protected countBySQLFragmentInternalAsync(
|
|
222
|
+
_queryInterface: any,
|
|
223
|
+
_tableName: string,
|
|
224
|
+
_sqlFragment: SQLFragment<TFields>,
|
|
225
|
+
): Promise<number> {
|
|
226
|
+
throw new Error('SQL fragment count not supported for StubDatabaseAdapter');
|
|
227
|
+
}
|
|
228
|
+
|
|
205
229
|
private generateRandomID(): any {
|
|
206
230
|
const idSchemaField = this.entityConfiguration2.schema.get(this.entityConfiguration2.idField);
|
|
207
231
|
invariant(
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
EntityDatabaseAdapterPaginationCursorInvalidError,
|
|
4
4
|
EntityMetricsLoadType,
|
|
5
5
|
getDatabaseFieldForEntityField,
|
|
6
|
+
timeAndLogCountEventAsync,
|
|
6
7
|
timeAndLogLoadEventAsync,
|
|
7
8
|
} from '@expo/entity';
|
|
8
9
|
import assert from 'assert';
|
|
@@ -190,6 +191,23 @@ export class EntityKnexDataManager<
|
|
|
190
191
|
);
|
|
191
192
|
}
|
|
192
193
|
|
|
194
|
+
async countByFieldEqualityConjunctionAsync<N extends keyof TFields>(
|
|
195
|
+
queryContext: EntityQueryContext,
|
|
196
|
+
fieldEqualityOperands: readonly FieldEqualityCondition<TFields, N>[],
|
|
197
|
+
): Promise<number> {
|
|
198
|
+
return await timeAndLogCountEventAsync(
|
|
199
|
+
this.metricsAdapter,
|
|
200
|
+
EntityMetricsLoadType.COUNT_EQUALITY_CONJUNCTION,
|
|
201
|
+
this.entityClassName,
|
|
202
|
+
queryContext,
|
|
203
|
+
)(
|
|
204
|
+
this.databaseAdapter.countByFieldEqualityConjunctionAsync(
|
|
205
|
+
queryContext,
|
|
206
|
+
fieldEqualityOperands,
|
|
207
|
+
),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
193
211
|
async loadManyBySQLFragmentAsync(
|
|
194
212
|
queryContext: EntityQueryContext,
|
|
195
213
|
sqlFragment: SQLFragment<TFields>,
|
|
@@ -211,6 +229,18 @@ export class EntityKnexDataManager<
|
|
|
211
229
|
);
|
|
212
230
|
}
|
|
213
231
|
|
|
232
|
+
async countBySQLFragmentAsync(
|
|
233
|
+
queryContext: EntityQueryContext,
|
|
234
|
+
sqlFragment: SQLFragment<TFields>,
|
|
235
|
+
): Promise<number> {
|
|
236
|
+
return await timeAndLogCountEventAsync(
|
|
237
|
+
this.metricsAdapter,
|
|
238
|
+
EntityMetricsLoadType.COUNT_SQL,
|
|
239
|
+
this.entityClassName,
|
|
240
|
+
queryContext,
|
|
241
|
+
)(this.databaseAdapter.countBySQLFragmentAsync(queryContext, sqlFragment));
|
|
242
|
+
}
|
|
243
|
+
|
|
214
244
|
/**
|
|
215
245
|
* Load a page of objects using cursor-based pagination with unified pagination specification.
|
|
216
246
|
*
|
|
@@ -450,17 +480,16 @@ export class EntityKnexDataManager<
|
|
|
450
480
|
baseWhere: SQLFragment<TFields> | undefined,
|
|
451
481
|
cursorCondition: SQLFragment<TFields> | null,
|
|
452
482
|
): SQLFragment<TFields> {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return sql`TRUE`;
|
|
483
|
+
if (!baseWhere) {
|
|
484
|
+
return cursorCondition ?? sql`TRUE`;
|
|
456
485
|
}
|
|
457
|
-
|
|
458
|
-
|
|
486
|
+
|
|
487
|
+
if (!cursorCondition) {
|
|
488
|
+
return baseWhere;
|
|
459
489
|
}
|
|
460
|
-
|
|
461
|
-
//
|
|
462
|
-
|
|
463
|
-
return sql`(${first}) AND ${second}`;
|
|
490
|
+
|
|
491
|
+
// Wrap baseWhere in parens when combining with cursor condition
|
|
492
|
+
return sql`(${baseWhere}) AND ${cursorCondition}`;
|
|
464
493
|
}
|
|
465
494
|
|
|
466
495
|
private augmentOrderByIfNecessary(
|