@konsumation/db v5.3.1
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
- defaultValues
- optionJSON
- mapAttributes
- mapAttributesInverse
- description
- Base
- Category
- MASTER
- SCHEMA_VERSION_1
- SCHEMA_VERSION_2
- SCHEMA_VERSION_CURRENT
- CATEGORY_PREFIX
- VALUE_PREFIX
- unit
- fractionalDigits
- Master
- Meter
- Note
- secondsAsString
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
objectObject target objectoptionsObject as passed to object constructor (optional, default{})propertiesObject object properties (optional, default{})attributesObject? attribute meta info (optional, defaultobject.constructor.attributes)
defaultValues
Get default values.
Parameters
Returns Object filled with default values
optionJSON
Create json based on present options. In other words only produce key value pairs if value is defined.
Parameters
objectObjectinitialObject (optional, default{})attributesObject to operator on (optional, defaultobject.constructor.attributes)
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
description
Description of the content.
Base
Base
Parameters
Properties
key
Returns string
write
- See: {key}
Writes object into database. Leaves all other entries alone.
Parameters
dblevelup
readDetails
Get detail objects.
Parameters
factoryClassdblevelupoptionsObject
Returns AsyncIterator\
delete
Delete record from database.
Parameters
dblevelup
keyPrefix
Prefix of the key
Returns string
keyPrefixWith
Parameters
objectBase
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
dblevelupprefixstringgtestring lowest name (optional, default"\u0000")ltestring highst name (optional, default"\uFFFF")
Returns AsyncIterator<Base>
entriesWith
Get instances with owner.
Parameters
dblevelupobjectObjectgtestring lowest name (optional, default"\u0000")ltestring highst name (optional, default"\uFFFF")
Returns AsyncIterator<Base>
entry
Get a single instance.
Parameters
dblevelupkeystring
Category
Extends Base
Value Category.
Parameters
Properties
namestring category namedescriptionstringunitstring physical unitfractionalDigitsnumber display precission
valueKey
Key for a given value.
Parameters
timenumber seconds since epoch
Returns string key
writeValue
Write a time/value pair.
Parameters
getValue
Parameters
dbleveluptimenumber seconds since epoch
deleteValue
Parameters
dbleveluptimenumber seconds since epoch
values
Get values of the category.
Parameters
dblevelupoptionsObject
Returns Iterator[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
readStream
Get values of the category as ascii text stream with time and value on each line.
Parameters
dblevelupoptionsObject
Returns Readable
meters
Get Meters of the category.
Parameters
dblevelupoptionsObject
Returns Iterator<Meter>
notes
Get Notes of the category.
Parameters
dblevelupoptionsObject
Returns AsyncIterator<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
schemaVersionstring
close
Close the underlaying database.
categories
List Categories.
Parameters
backup
Copy all data into out stream as long time text data.
Parameters
outWriteable
restore
Restore database from input stream.
Parameters
inputReadable data from backup
initialize
Initialize database. checks/writes master record.
Parameters
dblevelup
Meter
Extends Base
Meter
Parameters
Properties
namestring category namedescriptionstringunitstring physical unitfractionalDigitsnumber display precission
Note
Extends Base
Hints placed on a category at a specific time.
Parameters
timeowneroptions
secondsAsString
Format seconds as string left padded with '0'.
Parameters
secondsnumber seconds since epoch
Returns string padded seconds
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago