0.0.3 • Published 4 years ago

leveldb-easy v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

leveldb-easy

leveldb-easy downloads

A simple LevelDB wrapper to store data.

Discord for bug/help: AcarSY#5341

API

db.get() db.set() db.has() db.update() db.delete()

Install

npm install leveldb-easy level levelup leveldown deasync eventemitter3

db.get()

const LevelDB = require("leveldb-easy");
const db = new LevelDB("./databaseName"); // do not write file extension (like .js, .sqlite, .json)

db.on("get", (data) => {
	/* data = {
		"key": "keyData",
		"isSuccessful": false // because keyData named data wasn't found.
	} */
});
db.get("keyData");

db.get(key)

DataType
keyString

return Boolean - String - Object (Array - Date - Plain Object), Number - undefined (like "test_1", 12, "test_2")

db.on("get", data)

DataType
"get"String
dataFunction - Arrow function

db.set()

const LevelDB = require("leveldb-easy");
const db = new LevelDB("./databaseName"); // do not write file extension (like .js, .sqlite, .json)

db.on("set", (data) => {
	/* data = {
		"key": "keyData",
		"value": {"value": "data"},
		"isSuccessful": true
	} */
});
db.set("keyData", {"value": "data"});

db.set(key, value)

DataType
keyString
valueBoolean - String - Object (Array - Date - Plain Object), Number

return Boolean (true)

db.on("set", data)

DataType
"set"String
dataFunction - Arrow function

db.has()

const LevelDB = require("leveldb-easy");
const db = new LevelDB("./databaseName"); // do not write file extension (like .js, .sqlite, .json)

db.has("keyData");

db.has(key)

DataType
keyString

return Boolean (true or false)

db.update()

const LevelDB = require("leveldb-easy");
const db = new LevelDB("./databaseName"); // do not write file extension (like .js, .sqlite, .json)

db.on("update", (data) => {
	/* data = {
		"key": "keyData",
		"fn": [Function] ((x => (x + 1))),
		"function": [Function] ((x => (x + 1))),
		"newValue": 85,
		"oldValue" 3,
		"isSuccessful": true // because keyData named data was found.
	} */
});
db.set("keyData", 3)
db.update("keyData", (x => (x + 82)));

db.update(key, data)

DataType
keyString
dataFunction - Arrow function (i recommend this)

return Boolean (true)

db.on("update", data)

DataType
"update"String
dataFunction - Arrow function

db.delete()

const LevelDB = require("leveldb-easy");
const db = new LevelDB("./databaseName"); // do not write file extension (like .js, .sqlite, .json)

db.on("delete", (data) => {
	/* data = {
		"key": "keyData",
		"isSuccessful": false // because keyData named data wasn't found.
	} */
});
db.delete("keyData")

db.delete(key)

DataType
keyString

return Boolean (true or false)

db.on("delete", data)

DataType
"delete"String
dataFunction - Arrow function

Changelog

  • A lot of typos in README were fixed. (x2)
  • README is changed.
  • Events were added. (eventemitter3)
  • Boolean support added.