@wsst/egg-mongoose
Version:
egg mongoose plugin
43 lines (35 loc) • 866 B
TypeScript
import * as mongoose from 'mongoose';
declare module 'egg' {
type MongooseModels = {
[key: string]: mongoose.Model<any>
};
type MongooseSingleton = {
clients: Map<string, mongoose.Connection>,
get (id: string) : mongoose.Connection
};
type MongooseConfig = {
url: string,
options?: mongoose.ConnectionOptions
};
// extend app
interface Application {
mongooseDB: mongoose.Connection | MongooseSingleton;
mongoose: typeof mongoose;
model: MongooseModels;
}
// extend context
interface Context {
model: MongooseModels;
}
// extend your config
interface EggAppConfig {
mongoose: {
url?: string,
options?: mongoose.ConnectionOptions,
client?: MongooseConfig,
clients?: {
[key: string]: MongooseConfig
}
};
}
}