npm i --save @nativescript-community/sqlite
- Version: 3.5.1
- GitHub: https://github.com/nativescript-community/sqlite
- NPM: https://www.npmjs.com/package/%40nativescript-community%2Fsqlite
- Downloads:
- Last Day: 20
- Last Week: 155
- Last Month: 1017
@nativescript-community/sqlite
SQLite for Nativescript
Table of Contents
Installation
Run the following command from the root of your project:
ns plugin add @nativescript-community/sqlite
Usage
You should take care of wrapping sqlite calls to your preferred async option (promises, observables, async/await). And catch any exceptions thrown.
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]
)
);
});