Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iobroker.sql

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iobroker.sql

Log state sql in a two-stages process (first to Redis, then to CouchDB)

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
308
decreased by-18.09%
Maintainers
1
Weekly downloads
 
Created
Source

Logo

ioBroker.sql

================================== NPM version Downloads Tests

NPM

This adapter saves state history into SQL DB.

Supports PostgreSQL, mysql, Microsoft SQL Server and sqlite. You can leave port 0 if default port is desired.

MS-SQL:

Use localhost\instance for host and check that TCP/IP connections are enabled. https://msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx

SQLite:

is "file"-DB and cannot manage too many events. If you have a big amount of data use real DB, like PostgreSQL and co.

MySQL:

You can install mysql on linux systems:

apt-get install mysql-server mysql-client 

mysql -uroot -p

CREATE USER 'iobroker‘@’%’ IDENTIFIED BY 'iobroker';
GRANT ALL PRIVILEGES ON * . * TO 'iobroker'@'%';
FLUSH PRIVILEGES;

If required edit /etc/mysql/my.cnf to set bind to IP-Address for remote connect.

Warning: iobroker user is "admin". If required give limited rights to iobroker user.

Structure of the DBs

Default Database name is "iobroker", but it can be changed in configuration.

Sources

This table is a list of adapter's instances, that wrote the entries. (state.from)

DBName in query
MS-SQLiobroker.dbo.sources
MySQLiobroker.sources
PostgreSQLsources
SQLitesources

Structure:

FieldTypeDescription
idINTEGER NOT NULL PRIMARY KEY IDENTITY(1,1)unique ID
namevarchar(255) / TEXTinstance of adapter, that wrote the entry

Note: MS-SQL uses varchar(255), and others use TEXT

Datapoints

This table is a list of datapoints. (IDs)

DBName in query
MS-SQLiobroker.dbo.datapoints
MySQLiobroker.datapoints
PostgreSQLdatapoints
SQLitedatapoints

Structure:

FieldTypeDescription
idINTEGER NOT NULL PRIMARY KEY IDENTITY(1,1)unique ID
namevarchar(255) / TEXTID of variable, e.g. hm-rpc.0.JEQ283747.1.STATE
typeINTEGER0 - number, 1 - string, 2 - boolean

Note: MS-SQL uses varchar(255), and others use TEXT

Numbers

Values for states with type "number". ts means "time series".

DBName in query
MS-SQLiobroker.dbo.ts_number
MySQLiobroker.ts_number
PostgreSQLts_number
SQLitets_number

Structure:

FieldTypeDescription
idINTEGERID of state from "Datapoints" table
tsBIGINT / INTEGERTime in ms till epoch. Can be converted to time with "new Date(ts)"
valREALValue
ackBIT/BOOLEANIs acknowledged: 0 - not ack, 1 - ack
_fromINTEGERID of source from "Sources" table
qINTEGERQuality as number. You can find description here

Note: MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.

Strings

Values for states with type "string".

DBName in query
MS-SQLiobroker.dbo.ts_string
MySQLiobroker.ts_string
PostgreSQLts_string
SQLitets_string

Structure:

FieldTypeDescription
idINTEGERID of state from "Datapoints" table
tsBIGINTTime in ms till epoch. Can be converted to time with "new Date(ts)"
valTEXTValue
ackBIT/BOOLEANIs acknowledged: 0 - not ack, 1 - ack
_fromINTEGERID of source from "Sources" table
qINTEGERQuality as number. You can find description here

Note: MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.

Booleans

Values for states with type "boolean".

DBName in query
MS-SQLiobroker.dbo.ts_bool
MySQLiobroker.ts_bool
PostgreSQLts_bool
SQLitets_bool

Structure:

FieldTypeDescription
idINTEGERID of state from "Datapoints" table
tsBIGINTTime in ms till epoch. Can be converted to time with "new Date(ts)"
valBIT/BOOLEANValue
ackBIT/BOOLEANIs acknowledged: 0 - not ack, 1 - ack
_fromINTEGERID of source from "Sources" table
qINTEGERQuality as number. You can find description here

Note: MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.

Custom queries

The user can execute custom queries on tables from javascript adapter:

sendTo('sql.0', 'query', 'SELECT * FROM datapoints', function (result) {
    if (result.error) {
        console.error(result.error);
    } else {
        // show result
         console.log('Rows: ' + JSON.stringify(result.result));
    }
});

Or get entries for the last hour for ID=system.adapter.admin.0.memRss

sendTo('sql.0', 'query', 'SELECT id FROM datapoints WHERE name="system.adapter.admin.0.memRss"', function (result) {
    if (result.error) {
        console.error(result.error);
    } else {
        // show result
        console.log('Rows: ' + JSON.stringify(result.result));
        var now = new Date();
        now.setHours(-1);
        sendTo('sql.0', 'query', 'SELECT * FROM ts_number WHERE ts >= ' + now.getTime() + ' AND id=' + result.result[0].id, function (result) {
            console.log('Rows: ' + JSON.stringify(result.result));
        });
    }
});

Get history

Additional to custom queries, you can use build in system function getHistory:

var end = new Date().getTime();
sendTo('sql.0', 'getHistory', {
    id: 'system.adapter.admin.0.memRss',
    options: {
        start:      end - 3600000,
        end:        end,
        aggregate: 'minmax' // or 'none' to get raw values
    }
}, function (result) {
    for (var i = 0; i < result.result.length; i++) {
        console.log(result.result[i].id + ' ' + new Date(result.result[i].ts).toISOString());
    }
});

Changelog

1.2.1 (2016-08-30)

  • (bluefox) Fix selector for SQL objects

1.2.0 (2016-08-30)

  • (bluefox) сompatible only with new admin

1.0.10 (2016-08-27)

  • (bluefox) change name of object from "history" to "custom"

1.0.10 (2016-07-31)

  • (bluefox) fix multi requests if sqlite

1.0.9 (2016-06-14)

  • (bluefox) allow settings for parallel requests

1.0.7 (2016-05-31)

  • (bluefox) draw line to the end if ignore null

1.0.6 (2016-05-30)

  • (bluefox) allow setup DB name for mysql and mssql

1.0.5 (2016-05-29)

  • (bluefox) switch max and min with each other

1.0.4 (2016-05-29)

  • (bluefox) check retention of data if set "never"

1.0.3 (2016-05-28)

  • (bluefox) try to calculate old timestamps

1.0.2 (2016-05-24)

  • (bluefox) fix error with io-package

1.0.1 (2016-05-24)

  • (bluefox) fix error with SQLite

1.0.0 (2016-05-20)

  • (bluefox) change default aggregation name

0.3.3 (2016-05-18)

  • (bluefox) fix postgres

0.3.2 (2016-05-13)

  • (bluefox) queue select if IDs and FROMs queries for sqlite

0.3.1 (2016-05-12)

  • (bluefox) queue delete queries too for sqlite

0.3.0 (2016-05-08)

  • (bluefox) support of custom queries
  • (bluefox) only one request simultaneously for sqlite
  • (bluefox) add tests (primitive and only sql)

0.2.0 (2016-04-30)

  • (bluefox) support of milliseconds
  • (bluefox) fix sqlite

0.1.4 (2016-04-25)

  • (bluefox) fix deletion of old entries

0.1.3 (2016-03-08)

  • (bluefox) do not print errors twice

0.1.2 (2015-12-22)

  • (bluefox) fix MS-SQL port settings

0.1.1 (2015-12-19)

  • (bluefox) fix error with double entries

0.1.0 (2015-12-14)

  • (bluefox) support of strings

0.0.3 (2015-12-06)

  • (smiling_Jack) Add demo Data ( todo: faster insert to db )
  • (smiling_Jack) change aggregation (now same as history Adapter)
  • (bluefox) bug fixing

0.0.2 (2015-12-06)

  • (bluefox) allow only 1 client for SQLite

0.0.1 (2015-11-19)

  • (bluefox) initial commit

License

The MIT License (MIT)

Copyright (c) 2015 bluefox

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 25 Sep 2016

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc