sequelizeInstance.ts 726 B

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