diff --git a/src/crud-operations.ts b/src/crud-operations.ts index b30dbc8..5468681 100644 --- a/src/crud-operations.ts +++ b/src/crud-operations.ts @@ -38,19 +38,23 @@ export interface CrudOperationsOpts { - select(filter?: CrudFilter, sorts?: Array, relations?: Array): Promise>; + select(filter?: CrudFilter, sorts?: Array, relations?: Array): Promise>>; count(filter?: CrudFilter): Promise; - selectFirst(filter?: CrudFilter, sorts?: Array, relations?: Array): Promise; + selectFirst( + filter?: CrudFilter, + sorts?: Array, + relations?: Array + ): Promise | undefined>; exist(filter?: CrudFilter): Promise; - selectById(id: ID, relations?: Array): Promise; + selectById(id: ID, relations?: Array): Promise | undefined>; } export interface InsertOperations { - insert(data: ROW | Array): Promise; + insert(data: ROW | Array): Promise>; } export interface UpdateOperations { @@ -107,7 +111,11 @@ export class CrudOperations, sorts?: Array, relations?: Array): Promise> { + async select( + filter?: CrudFilter, + sorts?: Array, + relations?: Array + ): Promise>> { const query = this.knexReplica(this.table).modify((queryBuilder) => { this.applyFilter(queryBuilder, filter); this.applySort(queryBuilder, sorts); @@ -139,7 +147,7 @@ export class CrudOperations, sorts?: Array, relations?: Array - ): Promise { + ): Promise | undefined> { const rows = await this.select({ ...filter, limit: 1 }, sorts, relations); return rows[0]; } @@ -149,7 +157,7 @@ export class CrudOperations): Promise { + async selectById(id: ID, relations?: Array): Promise | undefined> { const include = { [this.idColumn]: id } as CrudFilterColumns; return this.selectFirst({ include }, undefined, relations); } @@ -157,7 +165,7 @@ export class CrudOperations): Promise { + async insert(data: ROW | Array): Promise> { // result is varying on dialect // mysql: the first one, sqlite3: the last one, ... // see http://knexjs.org/#Builder-insert diff --git a/src/weaver.ts b/src/weaver.ts index c7cef24..b663a04 100644 --- a/src/weaver.ts +++ b/src/weaver.ts @@ -26,7 +26,7 @@ export class Weaver { this.logger = LoggerFactory.getLogger('fastdao:weaver'); } - async weave(rows?: Array, relations?: Array): Promise> { + async weave(rows?: Array>, relations?: Array): Promise>> { if (!rows || rows.length === 0 || !relations || relations.length === 0) { // nothing to weave return []; @@ -64,9 +64,9 @@ export class Weaver { return rows; } - async selectRelationByIds(relation: Relation, ids: Array): Promise> { + async selectRelationByIds(relation: Relation, ids: Array): Promise>> { const missedIds: Array = []; - const hitRows: Array = []; + const hitRows: Array> = []; if (this.cache) { const cached: Array = ids && ids.length ? await this.cache.getAll(ids.map((id) => relation.table + ':' + id)) : [];