qm. Base
Source: qminerdoc.
Represents the database and holds stores.
new Base(paramObj)
Base
Example
// import qm module
var qm = require('qminer');
// using a constructor, in open mode
var base = new qm.Base({ mode: 'open' });
base.close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
paramObj |
|
The base constructor parameter object. |
Methods
close() → null
Closes the database.
Example
// import qm module
var qm = require('qminer');
// using a constructor, in open mode
var base = new qm.Base({ mode: 'open' });
// close the database
base.close();
- Returns
-
null
B No value is returned.
createStore(storeDef[, storeSizeInMB]) → (module:qm.Store or Array of module:qm.Store)
Creates a new store.
Example
// import qm module
var qm = require('qminer');
// create a new base with one store
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "Superheroes",
fields: [
{ name: "Name", type: "string" },
{ name: "Superpowers", type: "string_v" },
{ name: "YearsActive", type: "int" }
]
}]
});
// create a new store called "Supervillains" in the base
base.createStore({
name: "Supervillians",
fields: [
{ name: "Name", type: "string" },
{ name: "Superpowers", type: "string_v" },
{ name: "YearsActive", type: "int" }
]
});
// create two new stores called "Cities" and "Leagues"
base.createStore([
{
name: "Cities",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "Population", type: "int" }
]
},
{
name: "Leagues",
fields: [
{ name: "Name", type: "string" },
{ name: "Members", type: "string_v" }
]
}
]);
base.close();
Parameters
Name | Type | Optional | Description |
---|---|---|---|
storeDef |
Array of module:qm~SchemaDef |
|
The definition of the store(s). |
storeSizeInMB |
number |
Yes |
The reserved size of the store(s). Defaults to |
- Returns
-
(module:qm.Store or Array of module:qm.Store)
B - Returns a store or an array of stores (if the schema definition was an array).
garbageCollect([max_time])
Calls qminer garbage collector to remove records outside time windows. For application example see module:qm~SchemaTimeWindowDef.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
max_time |
number |
Yes |
Maximal number of time each store can spend on cleaning backlog in milisecons. If -1 then no limit is applied. Defaults to |
getStats() → module:qm~PerformanceStatBase
Retrieves performance statistics for qminer.
Example
// import qm module
var qm = require('qminer');
// create a base with two stores
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "KwikEMart",
fields: [
{ name: "Worker", type: "string" },
{ name: "Groceries", type: "string_v" }
]
},
{
name: "NuclearPowerplant",
fields: [
{ name: "Owner", type: "string" },
{ name: "NumberOfAccidents", type: "int" },
{ name: "Workers", type: "string_v" }
]
}]
});
// call the garbage collector
base.getStats();
base.close();
- Returns
-
module:qm~PerformanceStatBase
B The performance statistics.
getStoreList() → Array of object
Returns a list of store descriptors.
Example
// import qm module
var qm = require('qminer');
// create a base with two stores
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "KwikEMart",
fields: [
{ name: "Worker", type: "string" },
{ name: "Groceries", type: "string_v" }
]
},
{
name: "NuclearPowerplant",
fields: [
{ name: "Owner", type: "string" },
{ name: "NumberOfAccidents", type: "int" },
{ name: "Workers", type: "string_v" }
]
}]
});
// get the list of store descriptors
var exists = base.getStoreList();
base.close();
- Returns
-
Array of object
B An array of store descriptors. The store descriptorstoreDesc
contains the properties:
1.storeDesc.storeId
- The store ID. Typenumber
.
2.storeDesc.storeName
- Store name. Typestring
.
3.storeDesc.storeRecords
- Number of records in store. Typenumber
.
4.storeDesc.fields
- The store field schema. TypeArray of module:qm.SchemaFieldDef
.
5.storeDesc.keys
- The store key schema. TypeArray of module:qm.SchemaKeyDef
.
6.storeDesc.joins
- The store join schema. TypeArray of module:qm.SchemaJoinDef
.
getStreamAggr(saName) → module:qm.StreamAggr
Gets the stream aggregate of the given name.
Example
// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gendre", type: "string" },
]
},
{
name: "Laser",
fields: [
{ name: "Time", type: "datetime" },
{ name: "WaveLength", type: "float" }
]
}]
});
// create a new time series window buffer stream aggregator for 'Laser' store (with the JSON object)
var wavelength = {
name: "WaveLengthLaser",
type: "timeSeriesWinBuf",
store: "Laser",
timestamp: "Time",
value: "WaveLength",
winsize: 10000
}
var sa = base.store("Laser").addStreamAggr(wavelength);
// get the stream aggregate with the name 'Laser'
var streamAggr = base.getStreamAggr('WaveLengthLaser');
base.close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
saName |
string |
|
The name of the stream aggregate. |
- Returns
-
module:qm.StreamAggr
B The stream aggregate whose name issaName
.
getStreamAggrNames() → Array of string
Gets an array of the stream aggregate names in the base.
Example
// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gendre", type: "string" },
]
},
{
name: "Laser",
fields: [
{ name: "Time", type: "datetime" },
{ name: "WaveLength", type: "float" }
]
}]
});
// create a new stream aggregator for 'People' store, get the length of the record name (with the function object)
var aggr = new qm.StreamAggr(base, new function () {
var length = 0;
this.name = 'nameLength',
this.onAdd = function (rec) {
length = rec.Name.length;
};
this.saveJson = function (limit) {
return { val: length };
}
}, "People");
// create a new time series window buffer stream aggregator for 'Laser' store (with the JSON object)
var wavelength = {
name: "WaveLengthLaser",
type: "timeSeriesWinBuf",
store: "Laser",
timestamp: "Time",
value: "WaveLength",
winsize: 10000
}
var sa = base.store("Laser").addStreamAggr(wavelength);
// get the stream aggregates names
var streamAggrNames = base.getStreamAggrNames();
base.close();
- Returns
-
Array of string
B The array containing the stream aggregate names.
getStreamAggrStats()
Retrieves performance statistics for stream aggregates.
isClosed() → Boolean
Checks if the base is closed.
Example
// import qm module
var qm = require('qminer');
// using a constructor, in open mode
var base = new qm.Base({ mode: 'open' });
// check if the base is closed
var closed = base.isClosed();
// close the database
base.close();
- Returns
-
Boolean
B Returnstrue
, if the base is closed.
isStore(name) → boolean
Checks if there is a store.
Example
// import qm module
var qm = require('qminer');
// create a base with two stores
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "KwikEMart",
fields: [
{ name: "Worker", type: "string" },
{ name: "Groceries", type: "string_v" }
]
},
{
name: "NuclearPowerplant",
fields: [
{ name: "Owner", type: "string" },
{ name: "NumberOfAccidents", type: "int" },
{ name: "Workers", type: "string_v" }
]
}]
});
// get the "KwikEMart" store
var exists = base.isStore("KwikEMart"); // true
base.close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
name |
string |
|
Store name. |
- Returns
-
boolean
B True, if there exists a store with the storename
. Otherwise, false.
loadCSV(opts[, callback])
Loads the store from a CSV file.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
opts |
|
Options object. |
|
callback |
function() |
Yes |
Callback function, called on errors and when the procedure finishes. |
partialFlush([window]) → number
Base saves dirty data given some time window.
Example
// import qm module
var qm = require('qminer');
// create a base with two stores
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "KwikEMart",
fields: [
{ name: "Worker", type: "string" },
{ name: "Groceries", type: "string_v" }
]
},
{
name: "NuclearPowerplant",
fields: [
{ name: "Owner", type: "string" },
{ name: "NumberOfAccidents", type: "int" },
{ name: "Workers", type: "string_v" }
]
}]
});
// call the garbage collector
base.partialFlush();
base.close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
window |
number |
Yes |
Length of available time window in miliseconds. Defaults to |
- Returns
-
number
B Number of records it flushed.
search(query) → module:qm.RecordSet
Makes a query search and returns a record set.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
query |
|
Query language JSON object. |
- Returns
-
module:qm.RecordSet
B The record set that matches the search criterion.
store(name) → module:qm.Store
Returns the store with the specified name.
Example
// import qm module
var qm = require('qminer');
// create a base with two stores
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "KwikEMart",
fields: [
{ name: "Worker", type: "string" },
{ name: "Groceries", type: "string_v" }
]
},
{
name: "NuclearPowerplant",
fields: [
{ name: "Owner", type: "string" },
{ name: "NumberOfAccidents", type: "int" },
{ name: "Workers", type: "string_v" }
]
}]
});
// get the "KwikEMart" store
var store = base.store("KwikEMart"); // returns the store with the name "KwikEMart"
base.close();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
name |
string |
|
Store name. |
- Returns
-
module:qm.Store
B The store.