feat: return Provide Typed

This commit is contained in:
MiaoWoo 2019-06-12 18:58:46 +08:00
parent 9fdb56dadb
commit a99a7b9d3b
3 changed files with 4 additions and 4 deletions

0
cli.sh Normal file → Executable file
View File

View File

@ -7,7 +7,7 @@ import { DBClient } from 'cc-server-db'
export class MongoDBClient<T = any> implements DBClient { export class MongoDBClient<T = any> implements DBClient {
private table: string; private table: string;
private db: Db; private db: Db;
private collection: Collection; private collection: Collection<T>;
constructor() { constructor() {
MongoDBConnection.getConnection((connection) => { MongoDBConnection.getConnection((connection) => {
@ -18,8 +18,8 @@ export class MongoDBClient<T = any> implements DBClient {
}); });
} }
public getProvide(): Db { public getProvide<P>(): P {
return this.db; return this.db as {} as P;
} }
public setTable(table: string): void { public setTable(table: string): void {

View File

@ -1,6 +1,6 @@
export const DBClient = Symbol.for('DBClient') export const DBClient = Symbol.for('DBClient')
export interface DBClient<T = any> { export interface DBClient<T = any> {
getProvide(): any; getProvide<P>(): P;
setTable(table: string): void; setTable(table: string): void;
find(filter: object): Promise<T[]>; find(filter: object): Promise<T[]>;
findOne(filter: Object): Promise<T>; findOne(filter: Object): Promise<T>;