Socket
Book a DemoInstallSign in
Socket

datarecorder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datarecorder

[![NPM Publish](https://github.com/shiveshnavin/datarecorder/actions/workflows/main.yml/badge.svg)](https://github.com/shiveshnavin/datarecorder/actions/workflows/main.yml)

1.0.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Data Recorder

NPM Publish

A simple library to record data in chunks.

Requirements

Database connection is required for using datarecorder. Refer to MultiDbOrm for more details

Supported databases:

  • MongoDB
  • Google Firestore
  • SQlite3

Install

Run in your NodeJS root

npm install -s datarecorder

Usage

Initialize the reocorder

Initialize with chunk size and multidb database connection.

  • chunkSize : Chunk size is the number of records which will be clubbed and flushed to database.
  • db : Optional. A MultiDbORM database connection. If db is not passed, a local file based sqlite db is used.

Example using SQLite

let recorder = require('datarecorder')

let chunkSize = 100;
let messageRecorder = recorder('myMessageRecorderID')
messageRecorder.init(chunkSize)

Example using firestore:

let recorder = require('datarecorder')

let chunkSize = 100;
const { MultiDbORM, FireStoreDB, MongoDB, SQLiteDB } = require("multi-db-orm");
let db = new FireStoreDB('./path/to/serviceaccount.json');

let messageRecorder = recorder('myMessageRecorderID',db)
messageRecorder.init(chunkSize)

Record data

After every chunkSize records the data will be flushed to database automatically. The objects recorded can be heterogenous.

messageRecorder.record({
    location:"Home",
    message:"An elephant entered the wardrobe"
})
messageRecorder.record({
    location:"Office",
    message:"The wabbit burnt the closet."
})

let urgentMessage = {
    imageUrl : 'http://example.com/elephant.png'
}
messageRecorder.record(urgentMessage)

Once you are done with recording the data or want to flush the data manually , you can explicitly flush using.

messageRecorder.flush()

Read Data

Reads the saved records in ascending order of time and returns an array.

let messages = await messageRecorder.read()
console.log('Read', messages.length, 'messages')

Delete Data

This will remove all the records for messageRecorder

let messages = await messageRecorder.delete()

FAQs

Package last updated on 26 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.