Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Since Version 3.0.0, all functions now use promises. Either use async/await (recommended), or use
.then
. See Usage.
⚠️ Versions <2.0.0 (v1 Format Databases) are not compatible with >=2.0.0 (v2 Format Databases). As of 2.1.0, a migration tool has been added. See the Migration section for details.
⚠️ Installing globally will force all databases to use the same key.
db.set(key, value)
- Set a value in the database.db.get(key)
- Get a value in the database.db.has(key)
- Returns true if the key has an associated value or is listed in the database, false if it doesn't exist.db.delete(key)
- Delete a value in the database.db.clear()
- Clear all values in the database.db.add(key, amount)
- Add a certain amount to a value in the database. Adds to 0 if a number isn't present.db.subtract(key, amount)
- Subtract a certain amount from a value in the database. Subtracts from 0 if a number isn't present.db.push(key, value)
- Pushes a value to an array. Makes a new array if an array isn't present.db.list(prefix)
- Lists all keys in the database that starts with a specific prefix. Lists every key if prefix is ommited.npm install omedb
or using shorthand
npm i omedb
Import with node require()
const OmeDB = require("omedb");
const db = new OmeDB()
const OmeDB = require("./index.js") // Imports the database.
const db = new OmeDB() // Initialises the database.
/*
==========================
ASYNCHRONOUS (RECOMMENDED)
==========================
*/
async function blah() { // This is not needed, just make sure you are running in an asynchronous function.
await db.clear() // Deletes all items in database.
await db.set("string", "A cool string!") // Sets a value in the database.
console.log(await db.get("string")) // A cool string!
/* --------------- Arrays --------------- */
console.log(await db.get("items")) // undefined
await db.push("items", "Sword") // Adds "Sword" to an array (is created if doesn't exist)
console.log(await db.get("items")) // [ 'Sword' ]
await db.push("items", "Coffee") // Adds "Coffee" to the array.
console.log(await db.get("items")) // [ 'Sword', 'Coffee' ]
/* --------------- Numbers --------------- */
await db.set("number", 31) // Sets "number" to 31.
console.log(await db.get("number")) // 31
await db.add("number", 10.5) // Adds 10.5 to "number" (if entry doesn't exist, it adds to 0.)
console.log(await db.get("number")) // 41.5
await db.subtract("number", 23) // Subtracts 23 from "number" if entry doesn't exist, it subtracts from 0.)
console.log(await db.get("number")) // 18.5
/* --------------- Database --------------- */
console.log(await db.list()) // Every key in the database, in our case it would be: ["string", "items", "number"], which could be iterated through and the value would be retrieved by using db.get(key).
// Setting entries for next example.
await db.set("entry1", "Hello!")
await db.set("entry2", "This is a")
await db.set("entry3", "database example")
await db.set("entry4", "where keys are listed")
await db.set("entry5", "by a prefix!")
console.log(await db.list('entry')) // Lists all keys starting with a specific prefix, in our case the prefix "entry" which would return: ["entry1", "entry2", "entry3", "entry4", "entry5"].
console.log(await db.has("entry5")) // true, as "entry5" exists within the database.
console.log(await db.has("entry6")) // false, as we have not yet added "entry6" to our database.
await db.delete("entry5") // returns with "true" if deletion was successful, "false" if it couldn't be deleted, or "undefined" if it does not exist.
}
blah();
/*
==========================
SYNCHRONOUS (USING .then().)
==========================
*/
db.clear() // Deletes all items in database.
db.set("string", "A cool string!") // Sets a value in the database.
db.get("string").then(value => {
console.log(value) // A cool string!
})
/* --------------- Arrays --------------- */
db.get("items").then(value => {
console.log(value) // undefined
db.push("items", "Sword") // Adds "Sword" to an array (is created if doesn't exist)
db.get("items").then(value => {
console.log(value) // [ 'Sword' ]
db.push("items", "Coffee").then(value => { // Adds "Coffee" to the array.
db.get("items").then(value => {
console.log(value) // [ 'Sword', 'Coffee' ]
})
})
})
})
/* --------------- Numbers --------------- */
db.set("number", 31) // Sets "number" to 31.
db.get("number").then(value => {
console.log(value) // 31
db.add("number", 10.5)// Adds 10.5 to "number" (if entry doesn't exist, it adds to 0.)
db.get("number").then(value => {
console.log(value) // 41.5
db.subtract("number", 23) // Subtracts 23 from "number" if entry doesn't exist, it subtracts from 0.)
db.get("number").then(value => {
console.log(value) // 18.5
})
})
})
/* --------------- Database --------------- */
db.list().then(value => {
console.log(db.list()) // Every key in the database, in our case it would be: ["string", "items", "number"], which could be iterated through and the value would be retrieved by using db.get(key).
})
// Setting entries for next example.
db.set("entry1", "Hello!")
db.set("entry2", "This is a")
db.set("entry3", "database example")
db.set("entry4", "where keys are listed")
db.set("entry5", "by a prefix!")
db.list('entry').then(value => {
console.log(db.list('entry')) // Lists all keys starting with a specific prefix, in our case the prefix "entry" which would return: ["entry1", "entry2", "entry3", "entry4", "entry5"].
})
db.has("entry5").then(value => {
console.log(value) // true, as "entry5" exists within the database.
})
db.has("entry6").then(value => {
console.log(value) // false, as we have not yet added "entry6" to our database.
})
db.delete("entry5") // returns with "true" if deletion was successful, "false" if it couldn't be deleted, or "undefined" if it does not exist.
To migrate a v1 Database to a v2 Database, use the following code.
const OmeDB = require("omedb")
const migrate = OmeDB.migrate
migrate() // Any errors will be printed in console.
console.log(db.list()) // OPTIONAL: Used to check whether or not migration was successful.
For configuration, use this format:
migrate(old file, new file)
Excluding any arguments will default them to the following:
migrate("omedb.odb", "db.odb")
For example:
migrate("olddatabase.odb", "newdatabase.odb")
migrate("dbv1.odb", "dbv2.odb")
migrate("hello.odb", "world.odb")
Versions >=3.0.0 have an API and a wrapper for said API. This is designed for databases running off a different server. Regular OmeDB will work seamlessly with the API.
var OmeDB = require("omedb")
var api = new OmeDB.api()
api.listen(3000) // Listens on port 3000 or the specified port. Defaults to 3654.
// Code here...
var Wrapper = require("omedb").wrapper
const db = new Wrapper("localhost", '3000') // Connects to API on localhost:3000. Make sure the port is the same as the API. Defaults to localhost:3654.
// Use DB as normal.
Version 1.0.0
Version 2.0.0
Version 2.1.0
Version 3.0.0
Version 3.0.1
FAQs
A simple, encrypted key-value database store.
The npm package omedb receives a total of 0 weekly downloads. As such, omedb popularity was classified as not popular.
We found that omedb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.