nativescript-sqlcipher
为 nativescript 应用程序提供的 Sqlcipher 插件。灵感来自 nativescript-sqlite 模块。
npm i --save nativescript-sqlcipher
- 版本:1.1.11
- GitHub: https://github.com/ZixiaoWang/nativescript-sqlcipher
- NPM: https://npmjs.net.cn/package/nativescript-sqlcipher
- 下载量
- 昨天: 0
- 上周: 0
- 上个月: 0
Nativescript Sqlcipher
为 nativescript 应用程序提供的 sqlcipher 模块。
灵感来自 NathanaelA/Nativescript-Sqlite
创建/打开数据库
在创建数据库之前,必须导入 nativescript-sqlcipher 模块。
var Database = require('nativescript-sqlcipher');
然后创建一个新数据库
var sqlcipher = new Database(dbname, options, callbackFn)
在 nativescript-sqlite 模块中,options
只支持 readOnly 属性,而现在 options 可以读取 key 属性作为数据库加密的 PRAGMA Key。
var options = {
readOnly: false,
key: 'Password' // key must be a string
}
如果缺少 key 属性,或者格式不正确,数据库将不会被加密。
示例
var Database = require('nativescript-sqlcipher');
var options = {
key: 'Password'
}
var sqlcipher = new Database('myDatabase', options); //sqlcipher is a Promise type
sqlcipher
.then( (db)=>{
db.execSQL('CREATE TABLE my_first_table (name TEXT, age INTEGER);');
})
.catch( (err)=>{
alert('Database creation failed.');
})
更新日志
01 Dec 2017
在 Xcode 9 中修复了编译错误
06 Oct 2017
将所有更新添加到 sqlcipher.ios.js 中,来自 NathanaelA/Nativescript-Sqlite。