kvite

A kv database based on uni-app plus.sqlite, support to add, delete, query, multi-database, multi-table, custom serializer, deserializer, etc

Github address: github.com/XiaoHuaShiF…

Quick start

Step 1 Import files

Copy kvite.js to a directory and import it

import Kvite from './kvite'
Copy the code

Step 2 Create the table

The first parameter is the database name and the second parameter is the table name

const userTable = await Kvite.buildDefaultKvite('testDb', 'user')
Copy the code

Step 3 add, delete, and revise

Put: Adds or modifies data

Note: Key is not processed by default and is converted to a string type. Value uses a JSON serializer by default

Await usertable.put (' red ', {gender: 'female ', age: 18})Copy the code

Get: Retrieves data or returns null if no data exists

Await usertable.get (' await ')Copy the code

Remove: deletes data

Await usertable.remove (' red ')Copy the code

API

The apis are all on the Kvite class, where a Kvite represents a table in a database

api Parameter 1 Type Parameter 2 Type Return value type instructions
static async buildDefaultKvite(dbName, tableName) String String Kvite Create a Kvite and it will be initialized automatically
async put(key, value) Object Object If no insert exists, update if it exists
async get(key) Object Object Gets the value, null is not returned
async remove(key) Object Remove the value
async containsKey(key) Object Boolean Whether the table contains keys
async clear() Clear the table
async size() Number Gets the number of records for the table
async keys() Array Obtain all keys. Array collection is returned
async keySet() Set Get all keys and return Set
async values() Array Obtain all values. Array collection is returned
async entries() Array Obtain all key-values. Array collection is returned
async map() Map<Object, Object> Get all key-values and return the Map collection
async isEmpty() Boolean Whether the table is empty
setKeySerializer(serializer) Object => Object Set the key serializer
setKeyDeserializer(deserializer) Object => Object Set up the key deserializer
setValueSerializer(serializer) Object => Object Set the value serializer
setValueDeserializer(deserializer) Object => Object Set the Value deserializer
getDbName() String Get the database name
getTableName() String The name of the table

Other apis, also on Kvite, used to implement the above API are risky and should be used with caution

api Parameter 1 Type Parameter 2 Type Return value type instructions
constructor(dbName, tableName) String String Kvite Constructor, which constructs a Kvite, needs to initialize itself
async init() Initialization (called when creating an instance from new Kvite())
async openDb() After opening the database, you can perform operations on the database
async closeDb() After the database is shut down, resources are released, and operations on the database fail
isOpenDb() Boolean Whether the database is open
async createTable() Create a table
async removeTable() Delete table
checkDb() Check whether the database is normal
async executeSQL(sql) String Perform SQL encapsulation
async selectSQL(sql) String {Array} Query the encapsulation of SQL