desc time author veaba
 *  import mongoose from 'mongoose' ; import { config , adminData , configOption } from "../config" ; import { UsersSchema } from "./model" ; import { _encryptedPWD , _md5 } from "../utils/utils" ; import { isEmptyArray } from '../utils/check' ; import { TheSchema } from './curd' ; const logger = require ( 'tracer' ) . console ( ) ; desc const connectMongo = async ( ) => { console . log ( '\x1B[32m%s\x1B[49m' , ' >     Mongodb服务已启动 √     ' ) ; mongoose . connect ( config . base + ':' + config . port + '/' + config . database , configOption , ( err ) => { if ( err ) { logger . warn ( 'mongodb 数据库链接失败，请检查' ) ; logger . warn ( err . message ) ; return ; } else console . log ( '\x1B[32m%s\x1B[49m' , ' >     Mongodb连接成功~~ √     ' ) ; } ) ; await mongoose . connection ; await checkInit ( ) ; } ; desc param obj { object } param collection_name const createDB = async ( obj , collection_name ) => { let model = TheSchema ( obj , collection_name ) ; return new Promise ( ( resolve , reject ) => { model . save ( ) . then ( ( res ) => { return resolve ( res ) ; } ) . catch ( ( err ) => { return reject ( err ) ; } ) ; } ) ; } ; desc const checkInit = async ( ) => { UsersSchema . find ( { phone : adminData . phone } ) . then ( async ( res ) => { if ( isEmptyArray ( res ) ) return await createDB ( { ... adminData , password : _encryptedPWD ( _md5 ( adminData . password ) ) } , 'users' ) ; } ) . catch ( ( err ) => { console . log ( err ) ; } ) ; } ; export { connectMongo } ;