|
| 1 | +<!-- ⚠️ This README has been generated from the file(s) "blueprint.md" ⚠️--> |
| 2 | +<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 4 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 5 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 8 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 9 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 10 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 11 | + DO NOT EDIT THIS READEME DIRECTLY! Edit "bluesprint.md" instead. |
| 12 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 13 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 14 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 15 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 16 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 17 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 18 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 19 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 20 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> |
| 21 | +<h1 align="center">@nativescript-community/sqlite</h1> |
| 22 | +<p align="center"> |
| 23 | + <a href="https://npmcharts.com/compare/@nativescript-community/sqlite?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@nativescript-community/sqlite.svg" height="20"/></a> |
| 24 | +<a href="https://www.npmjs.com/package/@nativescript-community/sqlite"><img alt="NPM Version" src="https://img.shields.io/npm/v/@nativescript-community/sqlite.svg" height="20"/></a> |
| 25 | + </p> |
| 26 | + |
| 27 | +<p align="center"> |
| 28 | + <b>SQLite for Nativescript</b></br> |
| 29 | + <sub><sub> |
| 30 | +</p> |
| 31 | + |
| 32 | +<br /> |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +[](#table-of-contents) |
| 37 | + |
| 38 | +## Table of Contents |
| 39 | + |
| 40 | +* [Installation](#installation) |
| 41 | +* [Usage](#usage) |
| 42 | + |
| 43 | + |
| 44 | +[](#installation) |
| 45 | + |
| 46 | +## Installation |
| 47 | +Run the following command from the root of your project: |
| 48 | + |
| 49 | +`ns plugin add @nativescript-community/sqlite` |
| 50 | + |
| 51 | + |
| 52 | +[](#usage) |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +You should take care of wrapping sqlite calls to your preferred async option (promises, observables, async/await). And catch any exceptions thrown. |
| 57 | + |
| 58 | +```typescript |
| 59 | +import { openOrCreate, deleteDatabase } from "@nativescript-community/sqlite"; |
| 60 | + |
| 61 | +const sqlite = openOrCreate("path/to/db"); |
| 62 | +sqlite.execute("CREATE TABLE names (id INT, name TEXT)"); |
| 63 | +sqlite.transaction(cancelTransaction => { |
| 64 | + // Calling cancelTransaction will rollback all changes made to db |
| 65 | + names.forEach((name, id) => |
| 66 | + sqlite.execute( |
| 67 | + "INSERT INTO names (id, name) VALUES (?, ?)", |
| 68 | + [id, name] |
| 69 | + ) |
| 70 | + ); |
| 71 | +}); |
| 72 | +``` |
0 commit comments