1234567891011121314151617181920212223242526272829303132333435363738 |
- import type { AccountModel } from './account/model'
- import type { Context } from './types'
- import type { HerdModel } from './herd/model'
- import { MongoClient } from 'mongodb'
- import type { TaskModel } from './task/model'
- import createAccountModel from './account/model'
- import createHerdModel from './herd/model'
- import createTaskModel from './task/model'
- export interface Models {
- account: AccountModel
- herd: HerdModel
- task: TaskModel
- }
- async function createDatabase(ctx: Context) {
-
- const mongo = await MongoClient.connect(ctx.config.mongo.uri)
- const db = mongo.db(ctx.config.mongo.db)
-
-
- const dbCtx = { ...ctx, mongo, db }
- const model = <Models>{
- account: await createAccountModel(dbCtx),
- herd: await createHerdModel(dbCtx),
- task: await createTaskModel(dbCtx),
- }
- return { mongo, db, model }
- }
- export default createDatabase
|