diff --git a/orm.d.ts b/orm.d.ts index ab187c3..60ab6d6 100644 --- a/orm.d.ts +++ b/orm.d.ts @@ -70,10 +70,10 @@ export declare abstract class Repo> { * * @protected */ - _findByParams(parameters: Record, limit?: number, order?: Record): Promise; - findMany(parameters: Record, order?: Record): Promise; + _findByParams(parameters: Record, limit?: number, order?: Record): Promise; + findMany(parameters: Record, order?: Record): Promise; shift(limit?: number, offset?: number): this; - count(query?: Record): Promise; + count(query?: Record): Promise; remove(entity: T, silent?: boolean): Promise; } @@ -81,10 +81,10 @@ export declare abstract class Repo> { declare abstract class Storage_2 { protected _dsn: string; constructor(dsn: string); - abstract find(name: string, query: Record): Promise; - abstract save(name: string, uniqKey: string, data: Record): Promise; + abstract find(name: string, query: Record): Promise; + abstract save(name: string, uniqKey: string, data: Record): Promise; abstract createSession(): StorageSession; - abstract count(name: string, query?: Record): Promise; + abstract count(name: string, query?: Record): Promise; abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise; } export { Storage_2 as Storage } @@ -99,8 +99,8 @@ export declare interface StorageCursor { /** @public */ export declare abstract class StorageSession { - abstract start(options?: Record): Promise; - abstract commit(fn: () => any, options?: Record): Promise; + abstract start(options?: Record): Promise; + abstract commit(fn: () => any, options?: Record): Promise; } /** @public */ diff --git a/src/app/repo.ts b/src/app/repo.ts index 7ab9ac2..a985389 100644 --- a/src/app/repo.ts +++ b/src/app/repo.ts @@ -74,9 +74,9 @@ export abstract class Repo> { * @protected */ async _findByParams( - parameters: Record, + parameters: Record, limit?: number, - order?: Record + order?: Record ): Promise { const cursor = await this._storage.find(this.Name(), parameters) if (limit && limit > 0) await cursor.limit(limit) @@ -90,7 +90,7 @@ export abstract class Repo> { return list } - async findMany(parameters: Record, order?: Record): Promise { + async findMany(parameters: Record, order?: Record): Promise { const cursor = await this._storage.find(this.Name(), parameters) if (this._offset > 0) await cursor.skip(this._offset) if (this._limit > 0) await cursor.limit(this._limit) @@ -110,7 +110,7 @@ export abstract class Repo> { return this } - async count(query?: Record): Promise { + async count(query?: Record): Promise { return this._storage.count(this.Name(), query) } diff --git a/src/app/storage.ts b/src/app/storage.ts index 9eb92a7..377b66b 100644 --- a/src/app/storage.ts +++ b/src/app/storage.ts @@ -20,19 +20,19 @@ export abstract class Storage { this._dsn = dsn } - abstract find(name: string, query: Record): Promise + abstract find(name: string, query: Record): Promise - abstract save(name: string, uniqKey: string, data: Record): Promise + abstract save(name: string, uniqKey: string, data: Record): Promise abstract createSession(): StorageSession - abstract count(name: string, query?: Record): Promise + abstract count(name: string, query?: Record): Promise abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise } /** @public */ export abstract class StorageSession { - abstract start(options?: Record): Promise - abstract commit(fn: () => any, options?: Record): Promise + abstract start(options?: Record): Promise + abstract commit(fn: () => any, options?: Record): Promise } diff --git a/src/app/storage/mongo.ts b/src/app/storage/mongo.ts index 7489e8c..44b00d4 100644 --- a/src/app/storage/mongo.ts +++ b/src/app/storage/mongo.ts @@ -21,19 +21,19 @@ export class MongoStorage extends Storage { await this._client.connect() } - async find(collectionName: string, query: Record): Promise { + async find(collectionName: string, query: Record): Promise { await this._connect() const coll = await this._client.db().collection(collectionName) return coll.find(query) } - async count(collectionName: string, query: Record): Promise { + async count(collectionName: string, query: Record): Promise { await this._connect() const coll = await this._client.db().collection(collectionName) return coll.countDocuments(query) } - async save(collectionName: string, uniqKey: string, data: Record): Promise { + async save(collectionName: string, uniqKey: string, data: Record): Promise { await this._connect() const id = data[uniqKey] const coll = await this._client.db().collection(collectionName)