How to set options when using better-sqlite3 with sqlcipher?
See original GitHub issueIssue type:
- question
- bug report
- feature request
- documentation issue
Database system/driver:
- cordova
- mongodb
- mssql
- mysql / mariadb
- oracle
- postgres
- sqlite / better-sqlite3-multiple-ciphers
- sqljs
- react-native
- expo
TypeORM version:
[x] 0.2.41 [ ] @next [ ] 0.x.x (or put your version here)
better-sqlite3-multiple-ciphers version: 7.4.5
- The following method is in effect (using
better-sqlite3-multiple-ciphers
)
// encrypt db
const db = require('better-sqlite3-multiple-ciphers')('foobar.db', { verbose: console.log })
db.pragma("cipher='sqlcipher'")
db.pragma(`rekey='secret-key'`)
db.prepare(`CREATE TABLE "post" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar NOT NULL, "text" varchar NOT NULL)`).run()
const stmt = db.prepare('INSERT INTO post (title, text) VALUES (?, ?)')
const info = stmt.run('Joey', 'my homie')
db.close()
// decrypt db
const db = require('better-sqlite3-multiple-ciphers')('foobar.db', { verbose: console.log });
db.pragma(`cipher='sqlcipher'`)
db.pragma("key='secret-key'");
const stmt = db.prepare("SELECT * FROM post")
console.log(stmt.get()); // { id: 1, title: 'Joey', text: 'my homie' }
- The following method is not valid (using
typeorm
)
import { createConnection } from 'typeorm'
import { BetterSqlite3ConnectionOptions } from 'typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions'
import { Post } from './entity/post'
const config: BetterSqlite3ConnectionOptions = {
type: 'better-sqlite3',
key: 'secret-key',
database: 'foobar.db',
driver: require('better-sqlite3-multiple-ciphers'),
entities: ['entity/*.ts'],
logging: true,
verbose: console.log,
prepareDatabase: db => {
db.pragma(`cipher='sqlcipher'`)
}
}
const start = async () => {
const conn = await createConnection(config)
const posts = await conn.manager.find(Post)
console.log(posts)
}
start() // SqliteError: file is not a database
I don’t know what’s wrong with my options for typeorm
.
Related to issue: https://github.com/m4heshd/better-sqlite3-multiple-ciphers/issues/4
The reproducible repo: https://github.com/yolopunk/typeorm-better-sqlite-sqlcipher
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Using sqlcipher with sqlite3 in Electron-Builder application
I am trying to create an encrypted database like this in my Electron application, const sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database('....
Read more >SQLCipher API - Zetetic LLC
Force SQLCipher to operate with the default settings consistent with that major version number as the default for the currently executing process (i.e....
Read more >better-sqlite3-sqlcipher - npm
Start using better-sqlite3-sqlcipher in your project by running `npm i better-sqlite3-sqlcipher`. There is 1 other project in the npm ...
Read more >Pragma statements supported by SQLite
So if you set the cache size using a negative number and subsequently ... This pragma returns the names of compile-time options used...
Read more >[nodejs]better-sqlite3 数据库加密 - 掘金
背景我们在使用electron 开发时,使用了better-sqlite3,但数据比较敏感, ... 2、How to set options when using better-sqlite3 with sqlcipher?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you guys!
@m4heshd Awesome! That is worked by verification. I could commit a pull request for fixed the bug!
Thank you very much!