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

nqm-iot-database-utils

v0.7.2

Published

Database Utility functions

Downloads

5

Readme

nqm-iot-database-utils npm versionBuild Status

nquiringminds IoT Database utilities (sqlite implementation for now)

Install

npm install nqm-iot-database-utils

Test

npm test

Build Documentation

npm run docs

nodejs

const sqliteUtils = require("nqm-iot-database-utils");

Usage

Example 1

The below example will do the following steps:

  1. Create a sqlite database in memory with openDatabase
  2. Create a dataset with two fields with createDataset
  3. Add 100 documents to the dataset with addData
  4. Retrieve a list documents for a given filter with getData
"use strict";

const sqliteUtils = require("nqm-iot-database-utils");
const TDX_SCHEMA = {
  "schema": {
    "dataSchema": {
      "prop1": {
        "__tdxType": ["number"],
      },
      "prop2": {
        "__tdxType": ["number"],
      },
    },
    "uniqueIndex": [],
  },
};

let dbIter;
const testData = [];

sqliteUtils.openDatabase("", "memory", "w+")
    .then((db) => {
      dbIter = db
      return sqliteUtils.createDataset(db, TDX_SCHEMA);
    })
    .then(() => {
      for (let idx = 0; idx < 100; idx++) {
        testData.push({
          prop1: idx,
          prop2: 100 - idx - 1,
        });
      }
      return sqliteUtils.addData(dbIter, testData);
    })
    .then(() => {
      return sqliteUtils.getData(dbIter,
        {$and: [{$or: [{prop1: {$gte: 2, $lte: 5}}, {prop1: {$gte: 92}}]}, {prop2: {$lte: 10}}]},
        null,
        {
          sort: {
            prop1: 1,
            prop2: -1,
          },
        });
    })
    .then((result) => {
      console.log(result);
    });

Example 2

The below example will add an ndarray to the dataset:

  1. Create a sqlite database in memory with openDatabase
  2. Create a dataset with two fields with createDataset
  3. Add 1 documents to the dataset with addData
  4. Retrieve the documents with getData
"use strict";

const sqliteUtils = require("nqm-iot-database-utils");
const TDX_SCHEMA = {
  "schema": {
    "dataSchema": {
      "timestamp": {
        "__tdxType": ["number"],
      },
      "array": {
        "__tdxType": ["ndarray"],
      },
    },
    "uniqueIndex": [],
  },
};

let dbIter;
const testData = [];

sqliteUtils.openDatabase("", "memory", "w+")
    .then((db) => {
      dbIter = db
      return sqliteUtils.createDataset(db, TDX_SCHEMA);
    })
    .then(() => {
      const array = new Float64Array(23 * 34);
      array.fill(-1.8934579345);
      let arrayData = sqliteUtils.getNdarrayMeta(Buffer.from(array.buffer), "float64", [23, 34]);
      return sqliteUtils.addData(dbIter, {timestamp: 123456789, array: arrayData});
    })
    .then(() => {
      return sqliteUtils.getData(dbIter, null, null, null);
    })
    .then((result) => {
      const row = result.data[0];
      const floatBuffer = sqliteUtils.getTypedArrayFromBuffer(row.array.data, "float64");
      console.log(floatBuffer);
    });

API