Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

nativescript-better-sqlite

0.3.2 • Public • Published

Nativescript-Better-Sqlite

A Nativescript plugin providing easy SQLite access on Android.

Installation:

tns plugin add nativescript-better-sqlite

What is working:

  • Create/connect database
  • In memory databases
  • Readonly databases
  • Prepared statements
  • Get single values
  • Iterator for rows
  • Get last inserted row
  • Pragmas

Example

The following code

import * as Sqlite from "nativescript-better-sqlite";
 
const database = new Sqlite.Database('users', { inMemory: true });
 
database.pragma('journal_mode = WAL');
 
database.execute(
    `CREATE TABLE
        user (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
              name TEXT NOT NULL);`
);
 
const insert = database.prepare('INSERT INTO user (name) VALUES (?)');
 
insert.run(['testName1']);
insert.run(['testName2']);
 
insert.close();
 
const names = database.prepare('SELECT * FROM user', true).all();
 
console.log(names);

results in

[
    {
        "name" : "testName1",
        "id" : 1
    },
    {
        "name" : "testName2",
        "id" : 2
    }
]

this output.

TODOs:

  • Transactions
  • Workers / async
  • Results as array
  • Optimisations

Install

npm i nativescript-better-sqlite

DownloadsWeekly Downloads

20

Version

0.3.2

License

MIT

Unpacked Size

23.7 kB

Total Files

5

Last publish

Collaborators

  • avatar