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

@hexalts/rdbc

v0.2.3-r5

Published

[![OSSAR](https://github.com/hexalts/rdbc/actions/workflows/ossar.yml/badge.svg)](https://github.com/hexalts/rdbc/actions/workflows/ossar.yml) [![CodeQL](https://github.com/hexalts/rdbc/actions/workflows/codeql.yml/badge.svg)](https://github.com/hexalts/

Downloads

36

Readme

OSSAR CodeQL CI

Make sure you have set up the RDB Server side. Please refer to this link.

Instalation

yarn add @hexalts/rdbc

Example


Once

Let's say you already have a MongoDB with collection cats with multiple documents of cat. You want to get it all for once.

First, you need to set up the RDB Configuration.

import RDB from '@hexalts/rdbc';

const instanceId = 'random UUIDv4'
const RDB = new RDB(
  {
    host: 'wss://broker.address.com:8883',
  },
  instanceId
);

You can try to generate an UUID v4 on this page, and make sure the client instanceId matches with the server instanceId. Otherwise it won't work.

Next step is to set up the database target and the collection we want to use.

const instance = RDB.Database('hexalts');
instance.Collection('cats');

Note that you only need to do this setup for once. It is dead simple. Then you can get all those cat like this.

const getAllCats = async () => {
  const result = await instance.Get();
  console.log(result);
};

getAllCats();

Stream

What if you want to listen to changes that affected any documents inside cats collection, while you get all documents inside cats collection at once? No worries, because it is as easy as this.

const watchThoseCats = async () => {
  const stream = instance.Stream('all');
  stream.on('data', (data) => {
    console.log(data);
  })
};

watchThoseCats();

Query

What if you want to get documents with multiple rules? Let's assume you have such documents

[
  {
    _id: '1',
    name: 'ciyo,
    age: 2,
    race: 'persian medium',
  },
  {
    _id: '2',
    name: 'izzy',
    age: 1,
    race: 'persian medium'
  },
  {
    _id: '3',
    name: 'mio,
    age: 3,
    race: 'persian medium'
  },
  {
    _id: '4',
    name: 'qio,
    age: 4,
    race: 'himalayan'
  },
]

Let's say you want to get any persian medium cats with age greater than 1. It goes like this.

const whereAreThoseCats = async () => {
  instance.Where('race', '==', 'persian medium')
  instance.Where('age', '>', 1)
  const stream = instance.Stream('all');
  stream.on('data', (data) => {
    console.log(data);
  });
};

whereAreThoseCats();

It will return

{
  _id: '1',
  name: 'ciyo,
  age: 2,
  race: 'persian medium',
}
{
  _id: '3',
  name: 'mio,
  age: 3,
  race: 'persian medium'
},

First, it will fetch you all documents which meets your rules. And then, once a document (which meets the rules) got changed, an event will be emitted over the stream.on with event name data, the data it emits is the one which got changed, it will not return the whole documents (which meets the rules) again because that will be inefficient.

Clear

A note to remember:

The Where() method actually push any query into the instance state, it means you need to Clear the Where condition to default every time you need a different query pattern.

But don't worry, because it is as easy as this.

instance.Clear();

Update

Let's say you inputted ciyo accidentally (it should be cio) and you want to update the document. Well, you got two ways to do that.

  1. If you know the document id.
const changeCatName = async () => {
  instance.Where('_id', '==', '1')
  const result = await instance.Update({ name: 'cio' });
  console.log(result);
};

changeCatName();
  1. If you don't remember the document id.
const changeCatName = async () => {
  instance.Where('name', '==', 'ciyo')
  const result = await instance.Update({ name: 'cio' });
  console.log(result);
};

changeCatName();

Delete

Let's say cio has just passed away and you want to move on, completely. Just like the Update method, you can use Where condition to delete it

  1. If you know the document id.
const changeCatName = async () => {
  instance.Where('_id', '==', '1')
  const result = await instance.Delete();
  console.log(result);
};

changeCatName();
  1. If you don't remember the document id.
const changeCatName = async () => {
  instance.Where('name', '==', 'ciyo')
  const result = await instance.Delete();
  console.log(result);
};

changeCatName();

Full API Documentation

For deeper understanding of Hexatls Realtime Database APIs, please refer to this dcumentation.