Spanish Total.js
Slovenčina
Dokumentácia Pre AI agentov
Obsah

Storage

Keep your own data of a driver in database tables and read it in reports.

.md Web

Táto stránka ešte nie je preložená. Čítaš originál.

Na tejto stránke

A driver can keep its own tables in the PostgreSQL database, for example every raw reading or the state of a parking lot. Declare the tables in exports.storage, and the platform creates them when you save the driver.

Declare a table

exports.storage = [{
    id: 'readings',
    name: 'Readings',
    columns: [
        { id: 'sn', name: 'Serial number', type: 'string' },
        { id: 'temperature', name: 'Temperature', type: 'number' }
    ]
}];

The column types are string, number, boolean, date (date and time), date2 (date only), smallint and integer. Every table also gets an id and a dtcreated column with the time of the insert.

When you change the columns and save the driver again, the platform adds, changes and removes the columns. Removing a table from exports.storage, or removing the driver, deletes the table and its data.

Insert a row

instance.storage.insert('readings', { sn: data.sn, temperature: temperature });

Only the declared columns are written. The id and dtcreated are filled in automatically.

Read the data

The tables are in the storage schema. Their names start with db, followed by a code made from the id of the driver and the id of the table. List them with this query in a report preview:

SELECT table_name FROM information_schema.tables WHERE table_schema = 'storage'

Then read a table in a report:

SELECT sn, temperature, dtcreated FROM storage.db1yr6f1treadings ORDER BY dtcreated DESC

See Keep every reading of a device in a report.

Vyrobené v Európe