1.5.11 • Published 4 years ago

slayer.db v1.5.11

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

What is this?

Easy to use database

Installation

npm i slayer.db

SlayersDBMongo

Basic Setup

//Import the class
import { slayersDBmongo } from "slayer.db";

// Create a new class of slayersDBmongo
const db = new slayersDBmongo({ options });

Set

// Takes a key and a value

db.set(key, value) --> // Key: String | Value: any;

deleteOne

// Delete one key from the database

db.deleteOne(key) --> // Key: String

deleteMany

// Exactly like "deleteOne" but deletes multiple

db.deleteMany(key) --> // Key: Array

has

// Check if the database has a key

db.has(key) --> // Key: String | Returns: Boolean

get

// Get a value by searching with key

db.get(key) --> // Key: String | Returns: Any;

deleteAll

// Delete everything from the database

db.deleteAll();

find

// Find data

db.find(); // Returns an array with all data

db.find({ Object }); // Returns an array with all data that has similar keys to the Object

reloadData

// Reload all data from the database
// NOTE: this is done on start up

db.reloadData();

findOneAndUpdate

// Name says its self..
// Find one and Update

db.findOneAndUpdate({find}, { toUpdate }, { options }) --> // Options have a default value of: { upsert: true }

SlayersDBJSON

Basic setup

import { slayersDBJSON } from "slayer.db";

// or

const { slayersDBJSON } = require("slayer.db");

// Create a new instance of the database

const data = new slayersDBJSON({ options }, [client]); --> // Client is optional

// DONT make new instances of the DB unless you plain on saving different data
// with the "saveInternal" option

Save

// No data will be saved for a restart until data.save() is used or db options say otherwise
// We recommend not saving too fast as it could corrupt the data, There is already a save cooldown

data.save() -> // Saves the data

Set

// Save the data with the set method

data.set(key, value);

// Advanced set

data.set("items.123", 10);

// Will save as: items: { 123: 10 }

Get

// Fetch set data with the get method

data.get(value) -> // If there is no data on the value undefined will be returned

// Advanced get

data.get('items.123')

// Gets In Object
// Gets format as: items: {123: value}
// Will return "value"

Has

//Check if the database has the key

data.has(key) -> // Returns a boolean

// Advanced

data.has('something.nested.very')

// Checks as:
// something: {nested: {very: }}

Delete

// Delete a key from the database

data.delete(key);

Clear

// Delete all saved data
// You cannot reverse this

data.clear();

Size

// Return how much data is saved

data.size -> // Returns a interger

Push

// Push more info into a value that is an Array

data.push(key, [WhatToPush]);

Splice

// Remove a certain element from an array

data.splice(key, query);

Clone

// Greate a clone of the entire Collection

data.clone() -> // Returns all methods

Add

// Add more to a number saved

data.add(key, Number);

Subtract

// Subtract a amount from a saved number

data.subtract(key, Number);

Table

// Create a new table and save data in different places

const table = new data.table({ options }, [client]) --> // Client is optional

Keys

// Returns an array of all saved keys

data.keys();

Values

// Returns an array of all saved values

data.values();

Random

// Returns randomly from all values
// Required the data.values() method

data.random() -> // Returns an Interger , String, Array

Random Key

// Returns randomly from all keys
// Required the data.keys() method

data.randomKey() -> // Returns an Interger , String, Array

Includes

// Serches through values

data.includes(query) -> // Returns a array if what includes the query

Includes Key

// Serches through keys

data.includesKey(query) -> // Returns a array if what includes the query

to JSON

// Returns all data in JSON format

data.toJSON({options}) -> // Returns a Object

Options

DB create

// When creating the instance of the db
new slayersDB({
  saveOnSet: false, // This will auto save when ever "data.set" is used

  saveOnUpdate: true, // Will save everytime the data updates
  // This option is highly recommended

  saveOnTimeout: {
    // This will save all the data on the timeout
    // NOTE: This will constantly keep your app alive
    func: true,
    timeout: 10 * 1000, // This will save on a 10 second interval
    // We do not recommended going anything under 5 seconds
    // If the app restarts before the interval runs again the data will not   be saved unless a "data.save" was used
  },
  saveOnDelete: false,
  // This will auto save the data when "data.delete" is used
  saveInternal: {
    func: true, // This is the toggle of it
    dir: "data", // This is the folder it should be stored in
    // Defualt dir is data folder. NOTE: dir stands for "directory"
    fileName: "db", // This is what the file will be called (DON'T add file extensions)
    // Default is "db"
  },
  // This will save the data outside of the node_modules folder
  // If you are using repl I highly recommend it
  // Either way this option is recommended for all users
  enableCooldown: false,
});

to JSON

data.toJson({
  straight: true, // This will format the way it is returned
});

SlayersEconomy

Basic setup

import { slayersEconomy } from "slayer.db";

// or

const { slayersEconomy } = require("slayer.db");

// Create a new instance of the database

const data = new slayersEconomy();

Save

// Make sure to use or the data wont be saved for a restart

data.save();

Add coins

// Add coins to a specific user

data.addCoins(userID, amount);

Remove coins

// Remove coins from a user

data.removeCoins(userID, amount);

Get Coins

// Get the amount of coins from a user

data.getCoins(userID);

Delete user

// Delete all users coins

data.deleteUser(userID);

Leader board

// Get a leaderboard on users

data.leaderBoard(amount);
// The amount is from how much must be returned
// If You put 10 the amount will be top 10
// Defualt is: 10

Clear

// Delete all data

data.clear();
1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.5.5

4 years ago

1.5.10

4 years ago

1.5.11

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.9

4 years ago

1.4.11

4 years ago

1.4.8

4 years ago

1.4.10

4 years ago

1.4.7

4 years ago

1.4.13

4 years ago

1.4.12

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.10

4 years ago

1.3.11

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.8

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.5.0

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.6.1

4 years ago

2.3.4

4 years ago

2.6.0

4 years ago

2.3.3

4 years ago

2.6.2

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago