Object built-in object

Object LevelDB

LevelDB database objects

Used to create and manage dictionary objects, the creation method:

1 2
var db = require("db"); var test = new db.openLevelDB("test.db");

Inheritance relationship

Member function

has

Check whether there is data with the specified key value in the database

1
Boolean LevelDB.has(Buffer key) async;

Call parameters:

  • key: Buffer, Specify the key value to be checked

Return result:

  • Boolean, Return whether the key value exists

get

Query the value of the specified key

1
Buffer 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

1
NArray 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 2
LevelDB.set(Buffer key, Buffer value) async;

Call parameters:

  • key: Buffer, Specify the key value to be set
  • value: Buffer, Specify the data to be set

mset

Set a set of key-value data, insert new data if the key-value does not exist

1
LevelDB.mset(Object map);

Call parameters:

  • map: Object, specify the key-value data dictionary to be set

mremove

Delete a set of specified key values

1
LevelDB.mremove(Array keys);

Call parameters:

  • keys: Array, specify the key value array to be deleted

remove

Delete all values ​​of the specified key value

1
LevelDB.remove(Buffer key) async;

Call parameters:

  • key: Buffer, Specify the key value to be deleted

forEach

Enumerate all key-value pairs in the database

1
LevelDB.forEach(Function func);

Call parameters:

  • func: Function, enumeration callback function

The callback function has two parameters, (value, key)

1 2 3 4 5 6
var 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 3
LevelDB.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 6
var 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

1
LevelDB LevelDB.begin();

Return result:

  • LevelDB, Return an open transaction object

commit

Commit the current transaction

1
LevelDB.commit();

close

Close the current database connection or transaction

1
LevelDB.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

1
String 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

1
Value LevelDB.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable