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

@replit/database

v3.0.1

Published

Client for Repl.it Database

Downloads

9,612

Readme

Replit Database Client

Run on Repl.it npm: @replit/database

The Replit Database client is a simple way to use Replit Database in your Node.js repls. The client expects to run within a Replit managed server context. Use this library in servers or other applications that execute on a Replit server, rather than in your user's browser.

Installation

Install the TypeScript Library with

npm install @replit/database

This library supports Bun, Deno, and Node.js (Node versions 18+ or any Node version polyfilled with the fetch API).

Quickstart

import Client from "@replit/database";

const client = new Client();
await client.set("key", "value");
let value = await client.get("key");

console.log(value); // { ok: true, value: "value" }

Docs

Initiate a new database client:

import Client from "@replit/database";

/**
 * Initiates Class.
 * @param {String} dbUrl Custom database URL
 */
new Client()

Retrieve a value for a key from the database:

/**
 * Gets a key
 * @param {String} key Key
 * @param {boolean} [options.raw=false] Makes it so that we return the raw string value. Default is false.
 * @returns Promise<OkResult<any> | ErrResult<RequestError>>
 */
const value = await client.get(key, /* options?: {raw: boolean} */)
console.log(value)
// { ok: true, value: "value" } | { ok: false, error: RequestError }

Sets a value for a key in the database:

/**
 * Sets a key
 * @param {String} key Key
 * @param {any} value Value
 */
await client.set(key, value)

Deletes a key from the database:

/**
 * Deletes a key
 * @param {String} key Key
 */
const result = await client.delete(key)
console.log(result.ok) // boolean

Lists all keys starting with the provided prefix:

/**
 * List key starting with a prefix if provided. Otherwise list all keys.
 * @param {String} prefix The prefix to filter by.
 */
const keys = await client.list("prefix-")
console.log(keys) // { ok: true, value: [...] } | { ok: false, error: RequestError }

Clears the database:

/**
 * Clears the database.
 * @returns a Promise containing this
 */
await client.empty()

Gets all records in the database:

/**
 * Get all key/value pairs and return as an object
 * @param {boolean} [options.raw=false] Makes it so that we return the raw
 * string value for each key. Default is false.
 */
const records = await client.getAll(/* options?: {raw: boolean} */)

Sets multiple key value pairs:

/**
 * Sets multiple keys from an object.
 * @param {Object} obj The object.
 */
await client.setMultiple({keyOne: "valueOne", keyTwo: "valueTwo"})

Deletes multiple keys from the database:

/**
 * Delete multiple entries by key.
 * @param {Array<string>} args Keys
 */
await client.deleteMultiple(['keyOne', 'keyTwo'])

Tests

npm i
npm run test