Object LevelDB
LevelDB database objects
Used to create and manage dictionary objects, the creation method:
1
2var db = require("db");
var test = new db.openLevelDB("test.db");
Inheritance
Member function
has
Check whether there is data with the specified key value in the database
1Boolean LevelDB.has(Buffer key) async;
Call parameters:
- key: Buffer, Specify the key value to be checked
Return result:
- Boolean, Returns whether the key value exists
get
Query the value of the specified key
1Buffer LevelDB.get(Buffer key) async;
Call parameters:
- key: Buffer, Specify the key value to be queried
Return result:
- Buffer, Returns the value corresponding to the key value, if it does not exist, returns null
mget
Query a set of specified key values
1NArray LevelDB.mget(Array keys);
Call parameters:
- keys: Array, specify the key value array to be queried
Return result:
- NArray, Returns an array containing key values
set
Set a key value data, insert new data if the key value does not exist
1
2LevelDB.set(Buffer key,
Buffer value) async;
Call parameters:
mset
Set a set of key-value data, insert new data if the key-value does not exist
1LevelDB.mset(Object map);
Call parameters:
- map: Object, specify the key-value data dictionary to be set
mremove
Delete a set of specified key values
1LevelDB.mremove(Array keys);
Call parameters:
- keys: Array, specify the key value array to be deleted
remove
Delete all values of the specified key value
1LevelDB.remove(Buffer key) async;
Call parameters:
- key: Buffer, Specify the key value to be deleted
forEach
Enumerate all key-value pairs in the database
1LevelDB.forEach(Function func);
Call parameters:
- func: Function, enumeration callback function
The callback function has two parameters, (value, key)
1
2
3
4
5
6var db = require("db");
var test = new db.openLevelDB("test.db");
test.forEach(function(value, key) {
...
});
between
Enumerate the key-value pairs between from and to in the database
1
2
3LevelDB.between(Buffer from,
Buffer to,
Function func);
Call parameters:
- from: Buffer, The minimum key value of the enumeration, this key value is included in the enumeration
- to: Buffer, The maximum key value of the enumeration, this key value is not included in the enumeration
- func: Function, enumeration callback function
The callback function has two parameters, (value, key)
1
2
3
4
5
6var db = require("db");
var test = new db.openLevelDB("test.db");
test.between("aaa", "bbb", function(value, key) {
...
});
begin
Start a transaction on the current database
1LevelDB LevelDB.begin();
Return result:
- LevelDB, Return an open transaction object
commit
Commit the current transaction
1LevelDB.commit();
close
Close the current database connection or transaction
1LevelDB.close() async;
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics
1String LevelDB.toString();
Return result:
- String, Returns the string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value LevelDB.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, Returns a value containing JSON serializable