sequelize / sequelize/sequelize

Using encryption (journeyapps/sqlcipher) in sqllite, there is no problem with normal use, but an error will be reported when using transactions

Open
#17,467 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending-approval
Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

Environment version

nodejs:V14.15.0
sqlite3@^5.1.4
journeyapps/sqlcipher@^5.3.1
sequelize@^6.29.0

This is the database related configuration

`
const path = require("path");
const { Sequelize } = require('sequelize');
const file = path.join(__dirname, '../ecg.db');
const LOG = require("./log4js").logger("SequelizeConnectDb");

const sequelize = new Sequelize({
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
dialect: 'sqlite',
storage: file,
dialectModulePath: '@journeyapps/sqlcipher',
logging: false,
logging: msg => LOG.info(msg)
});

sequelize.query('PRAGMA cipher_compatibility = 3');
sequelize.query("PRAGMA key = 'xxx'");

//使用 .authenticate() 函数测试连接是否正常
sequelize.authenticate().then(() => {
LOG.info('Connection has been established successfully.')
}).catch(err => {
LOG.error('Unable to connect to the database:', err)
})

module.exports = sequelize;
`

Using transactions will result in an error

`
let transaction = null;
let ecgEntity = null;
let hasError = false;
let err = null;
try {
transaction = await sequelize.transaction();
ecgEntity = await ecg.create(this.buildEcgData(ecgInfo, user), { transaction });

        await ecg.update({ filePath: AppConfig.getHolterRootPath(ecgEntity.id) }, { where: { id: ecgEntity.id }, transaction });
        await bpDetail.bulkCreate(this.buildBpData(ecgEntity, bpList), { transaction });
    } catch (e) {
        await transaction.rollback();
    }

`

Error Message

'SQLITE_NOTADB: file is not a database'
'Error\n at Database. (F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\dialects\sqlite\query.js:185:27)\n at Database.callbackTrampoline (internal/async_hooks.js:129:14)\n at F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\dialects\sqlite\query.js:183:50\n at new Promise ()\n at Query.run (F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\dialects\sqlite\query.js:183:12)\n at F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\seque…CGBP\trunk\holter-bp\node_modules\sequelize\lib\dialects\abstract\query-interface.js:308:21)\n at async model.save (F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\model.js:2490:35)\n at async Function.create (F:\Code\ECGBP\trunk\holter-bp\node_modules\sequelize\lib\model.js:1362:12)\n at async DBService.beginImport (F:\Code\ECGBP\trunk\holter-bp\areas\system\service\ecgFileService.js:92:25)\n at async F:\Code\ECGBP\trunk\holter-bp\areas\system\service\ecgFileService.js:542:35'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the transaction in areas/system/service/ecgFileService.js with the listed Node.js, sqlite3, SQLCipher, and Sequelize versions, then inspect the stack around node_modules/sequelize/lib/dialects/sqlite/query.js:183-185. Confirm whether the encrypted database opens normally but fails during transaction queries, and establish the minimal reproducible scope and expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, sqlite
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.