I managed to get sensor data into a sqlite3 database. Every 2 minutes new values appear in the database. Now I want to display it with chart.js and therefore make use of sql.js The code I use is:
const config_sqljs = {
locateFile: filename => (
'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/sql-wasm.wasm'
)
}
const sqlPromise = initSqlJs(config_sqljs)
const dataPromise = fetch((
'/sensors.db'
))
.then(res => res.arrayBuffer())
Promise.all([sqlPromise, dataPromise])
.then(([SQL, buf]) => {
const db = new SQL.Database(new Uint8Array(buf))
//const res = db.exec('select time_,temp,humi from sensors where topic=\"/x/sensors\"')
const res = db.exec('select time_,temp,humi from sensors where topic =\"/y/sensors\" and (date=\"29.11.2021\" or date=\"30.11.2021\" or date=\"01.12.2021\");')
const values = res[0].values;
let labelx = values.map((arr) => arr[0]);
let y = values.map((arr) => arr[1]);
let y2 = values.map((arr) => arr[2]);
})
It works well at first, but then I realized that the values in the arrays labelx, y, and y2 are not the newest one, they lack beheind, about half a day. The new values alwasy appear in the database. I think it has todo something with Promise.all() and .then but unfortunally I don't know much about js. The code is executet each time the site loads or reloads, even I I use Strg+F5 to force a complete, uncached reload it stays the same. Can you help me? Thanks!
=== EDIT ===
I adapted your suggestion:
const dataPromise = fetch((
'/db.db', {
method: "GET",
"cache-control": "no-store"}
))
.then(res => res.arrayBuffer())´
Sadly I get the error:
Uncaught (in promise) Error: file is not a database
the relevant line:
const res = db.exec('select x from db;')