Giter Site home page Giter Site logo

bri's Introduction

Bri: Bigdata Repository of Intelligence

This Bri database provides an easy-to-use interface for performing CRUD (Create, Read, Update, Delete) operations on documents. It also includes additional features such as subscribing to document changes and populating attributes with IDs.

Note: All documents, when created, are assigned a unique $ID in the form of four capitalized letters, representing the first two and last two characters of the document type name, followed by an underscore and then 7 base 32 characters (in Crockford encoding format). There is also a createdAt and updatedAt timestamp managed by the database that cannot be modified by the client.

Table of Contents

Installation

You can install the NoSQL Database Library using npm or other package managers. For npm, run the following command:

npm install nosql-db-library

For Yarn, run:

yarn add nosql-db-library

Make sure to replace nosql-db-library with the actual name of the library when it is published.

Usage

First, you need to import the library in your JavaScript or TypeScript project:

const db = require('nosql-db-library');

For TypeScript or ECMAScript modules, use:

import * as db from 'nosql-db-library';

After importing the library, you can use the provided action functions to interact with the database.

Action Functions

There are five action functions for interacting with the database:

  • sub: Subscribe to changes in documents.
  • get: Retrieve a document.
  • add: Insert a new document.
  • set: Replace an existing document.
  • del: Delete a document.

Document Retrieval Behavior

  • If a capital "S" is appended to the action function (e.g., db.get.fooS()), all matching documents are returned.
  • Otherwise, only the first matching document is returned.

Additional Properties for Retrieved Records

Retrieved records have two additional properties:

  • save(): Persist any changes made to the current document.
  • .and.: Populate an attribute with IDs, e.g., const userWithPopulatedFriendsList = await user.and.friends().

Examples

Adding a Document

db.add.foo({ a: { b: [1, 2] } }).then((foo) => {
  console.log("foo", foo);
});

Retrieving a Document

db.get.foo("<document-id>").then((foo) => {
  console.log("foo", foo);
});

Updating a Document

db.get.foo("<document-id>")
  .then((foo) => {
    foo.a.b.push(3);
    return foo.save();
  })
  .then((updatedFoo) => {
    console.log("updatedFoo", updatedFoo);
  });

Deleting a Document

db.del.foo("<document-id>").then(() => {
  console.log("Document deleted");
});

Subscribing to Changes

db.sub
  .user((x) => console.log("->", x))
  .then((unsub) => {
    // Perform operations here and then unsubscribe
    unsub();
  });

Populating Attributes

const userWithPopulatedFriendsList = await user.and.friends();
console.log(userWithPopulatedFriendsList);

For more detailed examples and usage scenarios, refer to the provided code snippets in the question.

bri's People

Watchers

Brian Shannon 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.