| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { Database } from "bun:sqlite";
- const meteostanicaDB = new Database("./data/meteostanica.sqlite");
- meteostanicaDB.run(`create table if not exists data (
- timestamp datetime default current_timestamp primary key,
- indoorTemp text not null,
- indoorPressure text not null,
- indoorHumidity text not null,
- indoorAltitude text not null,
- outdoorConnected integer not null,
- outdoorTemp text not null,
- outdoorPressure text not null,
- outdoorHumidity text not null,
- outdoorAltitude text not null
- );`)
- export default class Meteostanica {
- static getData() {
- const statement = meteostanicaDB.prepare(`
- SELECT *
- FROM data
- ORDER BY timestamp DESC;
- `)
- const result = statement.all();
- return result
- }
- static getDataProperty(property) {
- const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
- if (!tableNames.find(i => i.name === property)) return null
- const statement = meteostanicaDB.prepare(`
- SELECT ${property}
- FROM data
- ORDER BY timestamp DESC
- LIMIT 10;
- `)
- const result = statement.all();
- return result
- }
- }
|