npm i --save @nativescript-community/sqlite
- 版本: 3.5.1
- GitHub: https://github.com/nativescript-community/sqlite
- NPM: https://npmjs.net.cn/package/%40nativescript-community%2Fsqlite
- 下载量
- 昨天: 13
- 上周: 117
- 上个月: 637
@nativescript-community/sqlite
SQLite for Nativescript
目录
安装
从您的项目根目录运行以下命令
ns plugin add @nativescript-community/sqlite
使用方法
您应该注意将 sqlite 调用包装到您偏好的异步选项(promises、observables、async/await)中。并捕获任何抛出的异常。
import { openOrCreate, deleteDatabase } from "@nativescript-community/sqlite";
const sqlite = openOrCreate("path/to/db");
sqlite.execute("CREATE TABLE names (id INT, name TEXT)");
sqlite.transaction(cancelTransaction => {
// Calling cancelTransaction will rollback all changes made to db
names.forEach((name, id) =>
sqlite.execute(
"INSERT INTO names (id, name) VALUES (?, ?)",
[id, name]
)
);
});