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

konsum-db

v3.4.5

Published

timeseries database on leveldb

Downloads

182

Readme

npm License minified size downloads Build Status Styled with prettier Commitizen friendly Known Vulnerabilities

konsum-db

timeseries database on leveldb

example

import levelup from "levelup";
import leveldown from "leveldown";

import { Master, Category } from "konsum-db";

async function example() {
 // open database
 const db = await levelup(leveldown("example.db"));
 const master = await Master.initialize(db);

 // create category named EV
 const ev = new Category("EV", master, { unit: "kWh" });
 await ev.write(master.db);
 
 // write entry
 await ev.writeValue(db, Date.now(), 77.34);
}

example();

API

Table of Contents

definePropertiesFromOptions

  • See: Object.definedProperties()
  • See: Object.getOwnPropertyDescriptor()

Create properties from options and default options. Already present properties (direct) are skipped. The attribute list from the class will be applied to the options and merged with the given set of properties.

class aClass {
  static get attributes() {
    return { with_default: { default: 77 }};
  }
}

definePropertiesFromOptions(new aClass());
// equivalent to
Object.definedProperties(new aClass(),{ with_default: { value: 77 }})

Parameters

  • object Object target object
  • options Object as passed to object constructor (optional, default {})
  • properties Object object properties (optional, default {})

setAttribute

Set Object attribute. The name may be a property path like 'a.b.c'.

Parameters

getAttribute

Deliver attribute value. The name may be a property path like 'a.b.c'.

Parameters

Returns any value associated with the given property name

optionJSON

Create json based on present options. In other words only produce key value pairs if value is defined.

Parameters

  • object Object
  • initial Object (optional, default {})
  • skip Array<string> keys not to put in the result (optional, default [])

Returns Object initial + defined values

mapAttributes

Rename attributes. Filters out null, undefined and empty strings.

mapAttributes({a:1},{a:"a'"}) // {"a'": 1}

Parameters

Returns Object keys renamed after mapping

mapAttributesInverse

Same as mapAttributes but with the inverse mapping. Filters out null, undefined and empty strings

Parameters

Returns Object keys renamed after mapping

Base

Base

Parameters

Properties

key

Returns string

write

  • See: {key}

Writes object into database. Leaves all other entries alone.

Parameters

  • db levelup

readDetails

Get detail objects.

Parameters

Returns Iterator<factory>

delete

Delete record from database.

Parameters

  • db levelup

keyPrefix

Prefix of the key

Returns string

keyPrefixWith

Parameters

Returns String prefix for a given (master) object

typeName

Name of the type in text dump

Returns string

attributes

Additional attributes to be persisted

entries

Get instances without owner.

Parameters

  • db levelup
  • prefix string
  • gte string lowest name (optional, default "\u0000")
  • lte string highst name (optional, default "\uFFFF")

Returns AsyncIterator<Base>

entriesWith

Get instances with owner.

Parameters

  • db levelup
  • object
  • gte string lowest name (optional, default "\u0000")
  • lte string highst name (optional, default "\uFFFF")
  • owner Object

Returns AsyncIterator<Base>

entry

Get a single instance.

Parameters

Returns Base

description

Description of the content.

Returns string

Category

Extends Base

Value Category.

Parameters

  • name string category name

  • options Object

    • options.description string
    • options.unit string physical unit like kWh or m3
    • options.fractionalDigits number display precission

Properties

valueKey

Key for a given value.

Parameters

  • time number seconds since epoch

Returns string key

writeValue

Write a time/value pair.

Parameters

getValue

Parameters

  • db levelup
  • time number seconds since epoch

deleteValue

Parameters

  • db levelup
  • time number seconds since epoch

values

Get values of the category.

Parameters

  • db levelup

  • options Object

    • options.gte string time of earliest value
    • options.lte string time of latest value
    • options.reverse boolean order

Returns Iterator<Object>

readStream

Get values of the category as ascii text stream with time and value on each line.

Parameters

  • db levelup

  • options Object

    • options.gte string time of earliest value
    • options.lte string time of latest value
    • options.reverse boolean order

Returns Readable

meters

Get Meters of the category.

Parameters

Returns Iterator<Meter>

notes

Get Notes of the category.

Parameters

Returns Iterator<Meter>

entries

Get categories.

Parameters

Returns AsyncIterator<Category>

MASTER

Prefix of the master record

Type: string

SCHEMA_VERSION_1

Outdated schema version

Type: string

SCHEMA_VERSION_2

Schema with type + name

Type: string

SCHEMA_VERSION_CURRENT

Schema version for newly created databases

CATEGORY_PREFIX

Prefix of the categories. Will be followed by the category name

Type: string

VALUE_PREFIX

Prefix of the values. Will be followed by the category name

Type: string

unit

Physical unit.

Returns string

fractionalDigits

Precission

Returns number

Master

Extends Base

Master record. Holds schema version.

Properties

close

Close the underlaying database.

categories

List Categories.

Parameters

backup

Copy all data into out stream as long time text data.

Parameters

  • out Writeable

restore

Restore database from input stream.

Parameters

  • input Readable data from backup

initialize

Initialize database. checks/writes master record.

Parameters

  • db levelup

Returns Master

Meter

Extends Base

Meter

Parameters

Properties

Note

Extends Base

Hints placed on a category at a specific time.

Parameters

  • time
  • owner
  • options

secondsAsString

Format seconds as string left padded with '0'.

Parameters

  • seconds number seconds since epoch

Returns string padded seconds