mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
23 lines
604 B
JavaScript
Executable File
23 lines
604 B
JavaScript
Executable File
import mongoose, { Schema } from "mongoose"
|
|
import fs from "fs"
|
|
import path from "path"
|
|
|
|
function generateModels() {
|
|
let models = {}
|
|
|
|
const dirs = fs.readdirSync(__dirname).filter(file => file !== "index.js")
|
|
|
|
dirs.forEach((file) => {
|
|
const model = require(path.join(__dirname, file)).default
|
|
|
|
if (mongoose.models[model.name]) {
|
|
return models[model.name] = mongoose.model(model.name)
|
|
}
|
|
|
|
return models[model.name] = mongoose.model(model.name, new Schema(model.schema), model.collection)
|
|
})
|
|
|
|
return models
|
|
}
|
|
|
|
module.exports = generateModels() |