nativescript-better-sqlite
NativeScript 插件,用于在 Android 上轻松使用 SQLite
npm i --save nativescript-better-sqlite

Nativescript-Better-Sqlite

一个提供 Android 上便捷 SQLite 访问的 Nativescript 插件。

安装

tns plugin add nativescript-better-sqlite

工作正常

  • 创建/连接数据库
  • 内存数据库
  • 只读数据库
  • 预处理语句
  • 获取单个值
  • 行迭代器
  • 获取最后插入的行
  • pragma

示例

以下代码

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);

结果为

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

此输出。

待办事项

  • 事务
  • 工作/异步
  • 结果作为数组
  • 优化