npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ez-repldb

v1.0.13

Published

Use Replit's database with ease with EZReplDB!

Downloads

8

Readme

Version Install size Minzipped size Downloads/month

EZReplDB

Easy Repl DB is a quick and easy way to interact with Replit's database with next to no set up required.

Using EZReplDB

const db = require("ez-repldb");

Yep, that's all you need to do, you can start using the database right away! (By default this will automatically connect to your database, however it is also possible to customise which database this connects to; see db.url.)

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.getAll();

Gets all the key-value pairs currently stored in the Replit database. Returns a promise which resolves to an object with its properties and their values as the key-value pairs stored in the Replit database (the object will be empty if the database has had no keys set or if an error occurs).

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

db.cache();

Caches all current keys. This speeds up get significantly (get itself will automatically cache values of keys that aren't already cached, and set will automatically update values in the cache). To disable using cached values within get, set db.cachingEnabled (see in properties below) to false. db.cache returns a promise when called that resolves to either true or false, depending on whether the method was able to connect to the database (true does not neccessarily indicate caching succeeded, however it does indicate it is highly likely it did).


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"

Properties

These are properties of the exported database object.


db.url;

This property allows you access to the full URL used by all database methods, you can actually set this to a different Repl's database URL and all the methods will interact with that database instead.

Note: You can get and set this property, seting it will also change the value of db.path.


db.host;

This property allows you to see the host of your Replit database (which will always be kv.replit.com).

Note: You can only get this property, seting it will not change its value.


db.path;

This property allows you to see the path of your Replit database.

Note: You can only get this property, seting it will not change its value (although it's value will be changed if db.url is altered).


db.cachingEnabled;

This property allows you to enable/disable (enabled, true, by default) caching. All values accessed are cached enabling much faster geting (at the cost of memory).