hexo-db

2.0.1 • Public • Published

hexo-db

An NPM Package helper to let you interact with your HexoShard database.

What is HexoDB?

An easy external database for your small projects, like Discord bots! HexoDB is:

  • Easy Connection
  • Simple
  • Fast read and writing data
    Read the full documentation below!

Getting Started

If you're interested to get your own database, you may visit our site by clicking here

Example

const Hexo = require("hexo-db");
const db = new Hexo.Database("https://db--username.repl.co")
 
db.set("foo", "bar")
.then(() => console.log("ID 'foo' is saved with the value 'bar'!"));
 
db.get("foo").then(data => {
  console.log(data) // Logs 'bar'
});

Built with

  • superagent - used to scrape your data!
  • Glitch - HexoDB started out here!
  • Repl.it - your HexoShard is hosted here!

Authors

Fizx - Initial work - Fizuku

License

This project is licensed under the Apache License 2.0 - see LICENSE.md for details.

Support

You may join our server— FizxCreations - a server for all my creations!

Documentation

  • Base
const { Database } = require("hexo-db");
const hexoshard = "your-url-here"
const db = new Database(hexoshard);

Methods

.add (key, value)

Adds a number to a key with a number value.

  • key: string
  • value: number
db.add("coins", 200).then(() => console.log("Added 200 coins"));

.all ()

Returns an array of all data.

db.all() // -> [Array]

.delete (key)

Deletes the value of the specified key. Then returns boolean.

  • key: string
db.delete("foo").then(() => console.log("Deleted! :("));

.get (key)

Returns the data of the specified key. If no data is found, it will return null.

  • key: string
  • Alias: .fetch()
db.get("foo").then(data => console.log("value of 'foo' is " + data))

.has (key)

Returns true if the key exists and has a value, else false

  • key: string
  • Alias: .exists()
db.has("foo").then(data => console.log(data)) // -> true || false

.push (key, element)

Will push a string through an array, if the value of the key specified is also an array.

  • key: string
  • element: string
db.set("foo", ["bar"]) // -> ["bar"]
db.push("foo", "foo") // -> ["bar", "foo"]

.set (key, value)

This function sets new data based on a key in the database. (When using dot notation, if the object doesn't exist it'll create one)

  • key: string
  • value: number || object || string || array || boolean (default: null)
  • Alias: .write()
db.set("foo", "bar").then(() => console.log("'foo's value is now 'bar'!"))

.math (key, operand, value)

Performs an operation and sets it.

  • key: string
  • operand: /, +, *, -, "add", "plus", "subtract", "minus", "mul", "multiply", "div", "divide"
  • value: number
db.math("coins", "-", 30).then(() => console.log("Subtracted 30 coins"));

.subtract (key, value)

Subtracts a number from the specified key.

  • key: string
  • value: number
db.subtract("coins", 30).then(() => console.log("Subtracted 30 coins"));

Package Sidebar

Install

npm i hexo-db

Weekly Downloads

14

Version

2.0.1

License

Apache License 2.0

Unpacked Size

24.5 kB

Total Files

6

Last publish

Collaborators

  • xfizuku