Giter VIP home page Giter VIP logo

better-replit-db's Introduction

npm version weekly downloads license

Run on Replit

Better Replit DB

Better Replit DB is a fork of the official Replit Database client, with the added benefit of the contents being cached in memory. This allows for much faster load read and write times than the regular client. It also uses await/async, just like the official client.

Moving from @replit/database to better-replit-db

Moving from @replit/database to better-replit-db is really easy. Simply replace these lines:

const Database = require("@replit/database");
const db = new Database();

with this:

const db = require("better-replit-db");

IT IS LITERALLY DOZENS OF TIMES FASTER THAN THE OFFICIAL LIB

Speed Comparison

20x Ops

Test better-replit-database @replit/database Times Faser
Creating a Client 16 ms 120 ms 7.5x
Setting a Value 80 ms 2858 ms 35.7x
Listing Keys 107 ms 1583 ms 14.8x
Getting a Value 25 ms 1349 ms 54.0x
Deleting a Value 199 ms 4046 ms 20.3x
Listing Keys 36 ms 1422 ms 39.5x
Ensuring Values are Escaped 35 ms 1350ms 38.6x

100x Ops

Coming Soon - Regular DB Host Gets Ratelimited

Get started

const db = require("better-replit-db");

db.set("key", "value").then(async () => {
	let key = await db.get("key");
	console.log(key);
});

Docs

class Client(String key?)

The key is the optional custom URL.

  • db.connect(String key) Returns another db object, but connects with the provided key.
    db.get("key").then(console.log);

Native Functions

These functions are specified in the replit DB.

  • get(String key, Object options?)

    Gets a key. Returns Promise.

    db.get("key").then(console.log);

    Or if you want to store raw data:

    db.get("key", { raw: true }).then(console.log);
  • set(String key, Any value)

    Sets a key to value. Returns Client.

    db.set("key", "value");

    Or if you want to set raw data:

    db.set("key", "value", { raw: true });
  • delete(String key)

    Deletes a key. Returns Client.

    db.delete("key");
  • list(String? prefix)

    Lists all of the keys.

    db.list();

    Or if you want all of the keys starting with prefix.

    db.list("prefix");

Dynamic Functions

These functions have been added by the original author.

  • empty()

    Clears the database. Returns Client

    db.empty();
  • getAll()

    Get all key/value pairs and return as an object.

    db.getAll();
  • setAll(Object obj)

    Sets the entire database through a key/value object. Returns Client

    db.setAll({key1: 'value1', key2: 'value2'});
  • deleteMultiple(...String args)

    Deletes multiple keys. Returns client.

    db.delete("key1", "key2", "key3");

Tests

npm i
npm run test

License

This software is under the MIT license

better-replit-db's People

Contributors

mrlapizgithub avatar piemadd avatar masad-frost avatar stellasphere avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.