mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
19 lines
476 B
JavaScript
Executable File
19 lines
476 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
|
|
|
|
models[model.name] = mongoose.model(model.name, new Schema(model.schema), model.collection)
|
|
})
|
|
|
|
return models
|
|
}
|
|
|
|
module.exports = generateModels() |