import { Sequelize, Transaction } from 'sequelize'; import { getDatabasePath } from '../preload/utils'; // doc: https://sequelize.org/docs/v6/getting-started/ const logging = () => {}; // const logging = // process.env.NODE_ENV === "production" ? () => {} : (msg) => console.log(msg); const sequelize = new Sequelize({ dialect: 'sqlite', storage: getDatabasePath(), logging, pool: { max: 20, min: 5, acquire: 100000, }, // 对于使用了数据库事务的接口,高并发下,容易锁库。下面是解决办法。 // fix SQLITE_BUSY: database is locked // https://github.com/sequelize/sequelize/issues/10304 transactionType: Transaction.TYPES.IMMEDIATE, }); export default sequelize;