@edgeros/jsre-async-sqlite3

0.0.2 • Public • Published

async-sqlite3

Description

This is a software package that asynchronously executes SQL business logic, based on sqlite3, with SQL executed only in a sub-thread.

Installation

npm install @edgeros/jsre-async-sqlite3

Instructions

Standard usage
const Database = require('@edgeros/jsre-async-sqlite3')  

const db = new Database(path.join(tempPath, 'test.db'), undefined, { verbose: true })
const createTable = `CREATE TABLE IF NOT EXISTS "test" (
      "id" VARCHAR(50) PRIMARY KEY ,
      "identification" VARCHAR(50) ,
      "name" VARCHAR(255) NOT NULL ,
      "type" VARCHAR(50) ,
      "arch" VARCHAR(50) ,
      "ip" VARCHAR(255) NOT NULL ,
      "port" INTEGER NOT NULL ,
      "password" VARCHAR(255) ,
      "tls" INTEGER DEFAULT 0,
      "createdTime" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     "created_by" TEXT ,"updated_by" TEXT ,"created_at" TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')) ,"updated_at" TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')) ,"deleted"    INTEGER   NOT NULL DEFAULT (0))`
await db.run(createTable)

await db.run(`INSERT INTO test (id,identification, name, ip, type, arch, port, password, tls) VALUES('${uuid().replace(/-/g, '')}', '123', 'by', '192.168.0.1', 'sylix', 'arch', 5555, '369369369', 0);`)

const rowId = await db.insert(`INSERT INTO test (id,identification, name, ip, type, arch, port, password, tls) VALUES('${uuid().replace(/-/g, '')}', '123', 'by', '192.168.0.1', 'sylix', 'arch', 5555, '369369369', 0);`)

await db.get('select * from test where ip = ? and type = ?;', '192.168.0.1', 'sylix')

await db.run('update test set type = ? where type = ?;', 'Linux', 'Windows')

await db.run('delete from test where type = ?;', 'sylix')


// get sub-thread config
await db.getConfig()
 

License

MIT

/@edgeros/jsre-async-sqlite3/

    Package Sidebar

    Install

    npm i @edgeros/jsre-async-sqlite3

    Weekly Downloads

    2

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    22.5 kB

    Total Files

    18

    Last publish

    Collaborators

    • clarkttfu
    • epmbot
    • xieyuanbin
    • chengyonbin