New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ez-repldb

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ez-repldb

Use Replit's database with ease with EZReplDB!

  • 1.0.3
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

EZReplDB

EZReplDB is a quick and easy way to interact with Replit's database with next to no set up.

Using EZReplDB

// require EZReplDB and store it in a variable
const db = require("ez-repldb");

Yep, that's all you need to do, you can start using the database right away!

Methods

These are methods of the exported database object.

Note: EZReplDB supports storage of all valid JSON datatypes.


db.set(String key, Any value);

Sets a key in the Replit database to value. Returns a promise which resolves to true or false, indicating the success of the operation.

db.set("key", 123).then(console.log);             // -> true/false (depending on if it worked or not)
console.log(await db.set("msg", "Hello world!")); // -> true/false (depending on if it worked or not)

db.set(Any[] keysAndValues);

Reads the input (one dimensionsal array) as key-value pairs and sets all the keys to their corresponding values in the Replit database. Returns a promise which resolves to true or false, indicating the success of the operation.

db.set("key", 123, "msg", "Hello world!").then(console.log);  // -> true/false (depending on if it worked or not)
console.log(await db.set("key", 123, "msg", "Hello world!")); // -> true/false (depending on if it worked or not)

db.get(String key);

Gets the value stored using key from the Replit database. Returns a promise which resolves to the value stored using the input key or null (if an error occurs or the key didn't exist).

db.get("key").then(console.log);  // -> 123/null (depending on if it worked or not)
console.log(await db.get("msg")); // -> "Hello world!"/null (depending on if it worked or not)

db.get(String[] keys);

Gets an array of values stored using the keys in keys from the Replit database. Returns a promise which resolves to an array of values stored using the input keys.

db.get("key", "msg").then(console.log);  // -> [ 123, "Hello world!" ]/null (depending on if it worked or not)
console.log(await db.get("key", "msg")); // -> [ 123, "Hello world!" ]/null (depending on if it worked or not)

db.delete(String key);

Deletes the value stored using key from the Replit database. Returns a promise which resolves to true or false, indicating the success of the operation.

db.delete("key").then(console.log);  // -> true/false (depending on if it worked or not)
console.log(await db.delete("msg")); // -> true/false (depending on if it worked or not)

db.delete(String[] keys);

Deletes the values stored using the keys in keys from the Replit database. Returns a promise which resolves to true or false, indicating the success of the operation.

db.delete("key", "msg").then(console.log);  // -> true/false (depending on if it worked or not)
console.log(await db.delete("key", "msg")); // -> true/false (depending on if it worked or not)

db.list();

Gets the keys currently stored in the Replit database. Returns a promise which resolves to an array containing the keys stored in the Replit database (the array will be empty if the database has had no keys set or if an error occurs).

db.list().then(console.log);  // -> [ "key", "msg" ]/[] (depending on if it worked or not)
console.log(await db.list()); // -> [ "key", "msg" ]/[] (depending on if it worked or not)

db.list(String prefix);

Gets the keys currently stored in the Replit database that start with the input prefix. Returns a promise which resolves to an array containing the keys stored in the Replit database that begin with the input prefix (the array will be empty if the database has had no keys set or if an error occurs).

db.list("k").then(console.log);  // -> [ "key" ]/[] (depending on if it worked or not)
console.log(await db.list("m")); // -> [ "msg" ]/[] (depending on if it worked or not)

db.clear();

Removes all key-value pairs from the Replit database. Returns a promise which resolves to an array indicating the success of deleting each key-value pair from the Replit database.

db.clear().then(console.log);  // -> [ true, true ]/[ false, false ] (depending on if it worked or not)
console.log(await db.clear()); // -> [ true, true ]/[ false, false ] (depending on if it worked or not)

db.getObject(Object object);

Retrieves the keys stored as properties within the input object from the Replit database and applies them to object. Returns a promise that resolves with the resulting object (note that Objects are passed by reference so this will actually alter the object passed in to the function).

const obj = {
	"key": null,
	"msg": null
};
db.getObject(obj).then(function() {
	console.log(obj); // -> { "key": 123, "msg": "Hello world!" }/{ "key": null, "msg": null } (depending on if it worked or not)
});
await db.getObject(obj);
console.log(obj);     // -> { "key": 123, "msg": "Hello world!" }/{ "key": null, "msg": null } (depending on if it worked or not)

db.applyObject(Object object);

Sets the keys stored as properties within the input object to their respcetive values and applies them to the Replit database. Returns a promise that resolves to true or false depending on the success of the operation.

const obj = {
	"key": 123,
	"msg": "Hello world!"
};
db.applyObject(obj).then(console.log);  // -> true/false (depending on if it worked or not)
console.log(await db.applyObject(obj)); // -> true/false (depending on if it worked or not)

db.import(String url);

Imports the key-value pairs from another Replit database using the input URL (to get this URL, in the shell of the Repl you would like to import the database from enter echo $REPLIT_DB_URL). Returns a promise that resolves the true or false depending on the success of the operation. Also logs to the console all imported keys and potentially unsuccessfully imported keys (or upon failure, during which operation the failure occurred).

db.import("https://kv.replit.com/some-arbitrary-string").then(console.log); // -> true

Also output:

Imported the following keys: "key", "msg"

Keywords

FAQs

Package last updated on 29 Nov 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc