import { MidwayConfig } from '@midwayjs/core';
import * as fsStore      from 'cache-manager-fs-hash';
export default {
  	// 数据库配置
  	sequelize: {
		dataSource: {
			// 第一个数据源，数据源的名字可以完全自定义
			default: {
				database: process.env.DB_NAME ?? 'xxx',
				username: process.env.MYSQL_UNAME ?? 'xxx',
				password: process.env.MYSQL_PWD ?? 'xxx',
				host: process.env.MYSQL_HOST ?? '192.168.18.67',
				port: Number(process.env.MYSQL_PORT ?? 3306),
				encrypt: false,
				logging: false,
				dialect: 'mysql',
				define: { charset: 'utf8' },
				timezone: '+08:00',
				pool: {
					max: Number(process.env.POOL_MAX ?? 10),
					min: Number(process.env.POOL_MIN ?? 2),
					acquire: 30000,
					idle: 30000,
                    evict:1000
				},
				/**
				 * [dialectOptions 其它参数]
				 * @type {Object}
				 */
				dialectOptions: {
					/**
					 * [dateStrings 让读取date类型数据时返回字符串而不是UTC时间]
					 * @type {Boolean}
					 */
					dateStrings: true,
					/**
					 * [typeCast 时间格式处理]
					 * @type {Boolean}
					 */
					typeCast:true,
				},
				entities: ['../components/AdminBase/src/models'],
				// 本地的时候，可以通过 sync: true 直接 createTable
				sync: false,
			},
    	},
		defaultDataSourceName:'default'
	},
    //缓存类
    cache: {
        store: fsStore,
        options: {
            path:'public/caches',
            ttl: 2 * 60 * 60,      //秒级单位
            subdirs: false,     //create subdirectories to reduce the
                               //files in a single dir (default: false)
            zip: true,         //是否启用压缩 (default: false)
            maxsize:1024*1024*1024
        },
    },
} as MidwayConfig