Class: Database


Database(dbURL)

quick.replit - Created by Lebyy_Dev.

Constructor

new Database(dbURL)

Inititates the quick.replit instance!

Parameters:
Name Type Description
dbURL string

Replit database URL.

Example
const { Database } = require("quick.replit");
const db = new Database("url");

Methods

(async) add(key, value, opsopt) → {Promise.<Boolean>}

Adds +1 to the the value of the key specified in the database!

Parameters:
Name Type Attributes Default Description
key string

key

value number

value

ops object <optional>
{}

Add options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
db.add("items", 200).then(() => console.log("Added 200 items"));

(async) all(opsopt) → {Promise.<Array>}

Returns everything from the database

Parameters:
Name Type Attributes Default Description
ops object <optional>
{}

All options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

limit number <optional>
0

Fetch data only upto the specified limit (0 = Unlimited).

Returns:
  • Type: Promise.<Array>
Example
let data = await db.all();
console.log(`There are total ${data.length} entries.`);

(async) clear(opsopt) → {Promise.<Boolean>}

Delete's all of the data from the database!

Parameters:
Name Type Attributes Default Description
ops object <optional>
{}

Clear options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
const data = await db.clear();

(async) delete(key, opsopt) → {Promise.<Boolean>}

Deletes a key from the database!

Parameters:
Name Type Attributes Default Description
key string

The key to set.

ops object <optional>
{}

Delete options.

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
db.delete("foo").then(() => console.log("Deleted data"));

(async) deleteAll(opsopt) → {Promise.<Boolean>}

Delete's all of the data from the database! (similar to the clear method)

Parameters:
Name Type Attributes Default Description
ops object <optional>
{}

DeleteAll options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
const data = await db.deleteAll();

(async) exists(key, opsopt) → {Promise.<Boolean>}

Checks if there is a data stored with the given key!

Parameters:
Name Type Attributes Default Description
key string

Key

ops object <optional>
{}

Exists options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
await db.exists("foo").then(console.log);

(async) exportToQuickDB(quickdb, opsopt) → {Promise.<Array.<any>>}

Export's all of the data from the database to quick.db!

Parameters:
Name Type Attributes Default Description
quickdb any

Quick.db instance

ops object <optional>
{}

export options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

limit number <optional>
0

Fetch data only upto the specified limit (0 = Unlimited).

Returns:
  • Type: Promise.<Array.<any>>
Example
const data = await db.exportToQuickDB(quickdb);

(async) exportToQuickMongo(quickmongo, opsopt) → {Promise.<Array.<any>>}

Export's all of the data from the database to quickmongo!

Parameters:
Name Type Attributes Default Description
quickmongo any

QuickMongo instance

ops object <optional>
{}

export options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

limit number <optional>
0

Fetch data only upto the specified limit (0 = Unlimited).

Returns:
  • Type: Promise.<Array.<any>>
Example
const data = await db.exportToQuickMongo(quickmongo);

(async) fetch(key, opsopt) → {Promise.<any>}

Fetches the value stored on the key from database!

Parameters:
Name Type Attributes Default Description
key string

The key to set.

ops object <optional>
{}

Get options.

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<any>
Example
await db.fetch("foo").then(console.log);

(async) get(key, opsopt) → {Promise.<any>}

Fetches the data from database!

Parameters:
Name Type Attributes Default Description
key string

Key

ops object <optional>
{}

Fetch options.

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<any>
Example
await db.get("foo").then(console.log);

(async) has(key, opsopt) → {Promise.<Boolean>}

Checks if there is a data stored with the given key! (Similiar to the exists method)

Parameters:
Name Type Attributes Default Description
key string

Key

ops object <optional>
{}

Has options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
await db.has("foo").then(console.log);

import(data, opsopt) → {Promise.<Boolean>}

Import's the specific data from another database into replit database!

Parameters:
Name Type Attributes Default Description
data Array

Data

ops object <optional>
{}

Import options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
const data = QuickDB.all();
db.import(data);

(async) listall(prefixopt, opsopt) → {Promise.<Array>}

Returns all of the key's from the database!

Parameters:
Name Type Attributes Default Description
prefix string <optional>
""

The prefix to listall keys from.

ops object <optional>
{}

TypeOf options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Array>
Example
await db.listall().then(console.log);

(async) math(key, operator, value, opsopt) → {Promise.<Boolean>}

Does a math calculation and stores the value in the database!

Parameters:
Name Type Attributes Default Description
key string

Data key

operator string

One of +, -, * or /

value number

The value, must be a number

ops object <optional>
{}

Math options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
db.math("items", "+", 200).then(() => console.log("Added 200 items"));

(async) ping(opsopt) → {Promise.<Object>}

Fetches the overall ping of quick.replit database in MS!

Parameters:
Name Type Attributes Default Description
ops object <optional>
{}

Ping options

Returns:

console.log("Average: ", ping.average);

  • Type: Promise.<Object>
Example
const ping = await db.ping();

(async) pull(key, value, opsopt) → {Promise.<Boolean>}

Pull's the specific value from an array to the key in the database!

Parameters:
Name Type Attributes Default Description
key string

Key

value string

Value

ops object <optional>
{}

Pull options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
const data = await db.pull("foo", "bar");

(async) push(key, value, opsopt) → {Promise.<Boolean>}

Pushe's the specific value into an array to the key in the database!

Parameters:
Name Type Attributes Default Description
key string

Key

value string

Value

ops object <optional>
{}

Push options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
const data = await db.push("foo", "bar");

(async) raw(opsopt) → {Promise.<Object>}

Returns raw data object from the database {key: value}!

Parameters:
Name Type Attributes Default Description
ops object <optional>
{}

Raw options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

limit number <optional>
0

Fetch data only upto the specified limit (0 = Unlimited).

Returns:
  • Type: Promise.<Object>
Example
await db.raw().then(console.log);

(async) set(key, value, opsopt) → {Promise.<Boolean>}

Sets a value to the specified key on the database!

Parameters:
Name Type Attributes Default Description
key string

The key to set.

value

The value to set on the key.

ops object <optional>
{}

Set options.

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
await db.set("foo", "bar").then(() => console.log("Saved data"));

(async) setMany(items, opsopt) → {Promise.<Array.<any>>}

Set's the value in each element of array to the key in each element of array!

Parameters:
Name Type Attributes Default Description
items Array

The Data Array.

ops object <optional>
{}

Set options.

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Array.<any>>
Example
const data = [
{ key: "test_1", value: "hello1" },
{ key: "test_2", value: "hello2" },
{ key: "test_3", value: "hello3" },
{ key: "test_4", value: "hello4" },
{ key: "test_5", value: "hello5" },
{ key: "test_6", value: "hello6" },
{ key: "test_7", value: "hello7" },
{ key: "test_8", value: "hello8" },
{ key: "test_9", value: "hello9" }
];
await db.setMany(data)

(async) startsWith(key, opsopt) → {Promise.<Array>}

Fetches everything from the database and sorts by given target!

Parameters:
Name Type Attributes Default Description
key string

Key

ops object <optional>
{}

StartsWith options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

limit number <optional>
0

Fetch data only upto the specified limit (0 = Unlimited).

Returns:
  • Type: Promise.<Array>
Example
const data = await db.startsWith("money", { sort: ".data" });

(async) subtract(key, value, opsopt) → {Promise.<Boolean>}

Subtract's 1 from the the value of the key specified in the database!

Parameters:
Name Type Attributes Default Description
key string

Key

value number

Value

ops object <optional>
{}

Add options

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<Boolean>
Example
db.subtract("items", 100).then(() => console.log("Removed 100 items"));

(async) type(key, opsopt) → {Promise.<("string"|"number"|"bigint"|"boolean"|"symbol"|"undefined"|"object"|"function"|"array")>}

Return's the value type of the key!

Parameters:
Name Type Attributes Default Description
key string

key

ops object <optional>
{}

Type options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<("string"|"number"|"bigint"|"boolean"|"symbol"|"undefined"|"object"|"function"|"array")>
Example
console.log(await db.type("foo"));

(async) typeof(key, opsopt) → {Promise.<("string"|"number"|"bigint"|"boolean"|"symbol"|"undefined"|"object"|"function"|"array")>}

Checks the type of value stored in the key! (Similar to type method)

Parameters:
Name Type Attributes Default Description
key string

The key to set.

ops object <optional>
{}

TypeOf options

Properties
Name Type Attributes Default Description
raw boolean <optional>
false

If set to true, it will return the raw un-parsed data.

sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Returns:
  • Type: Promise.<("string"|"number"|"bigint"|"boolean"|"symbol"|"undefined"|"object"|"function"|"array")>
Example
await db.typeof("foo").then(console.log);

uptime() → {Promise.<Number>}

Returns database connection uptime!

Returns:
  • Type: Promise.<Number>
Example
console.log(`Database is up for ${db.uptime} ms.`);

(async) write(key, value, opsopt)

Writes a value to the specified key on the database (Similar to set)!

Parameters:
Name Type Attributes Default Description
key string

The key to set.

value string

The value to set on the key.

ops object <optional>
{}

Write options.

Properties
Name Type Attributes Default Description
sleep number <optional>
3500

Alter the time to sleep for if the response code is 429.

Example
await db.write("foo", "bar").then(() => console.log("Saved data"));

Events

debug

Emitted on debug mode

Parameters:
Name Type Description
Message string

Debug message

Example
db.on("debug", console.log);

error

Emitted when database encounters error

Parameters:
Name Type Description
Error Error

Error Message

Example
db.on("error", console.error);

ready

Emitted when database creates connection

Example
db.on("ready", () => {
    console.log("Successfully connected to the database!");
});