LoRaWAN-Signal-Mapping/server/Repos.SQLite/ReadingRepo.mjs

38 lines
761 B
JavaScript
Raw Normal View History

"use strict";
class ReadingRepo {
constructor({ database, RSSIRepo }) {
this.db = database;
this.RSSIRepo = RSSIRepo;
}
add(reading) {
if(typeof this.query_insert == "undefined")
this.query_insert = this.db.prepare(`INSERT INTO readings (
id,
lat, long,
data_rate, code_rate
) VALUES (
:id,
:latitude,
:longitude,
:data_rate, :code_rate
)`);
let new_id = this.insert_query.run(reading).lastInsertRowid;
// Attach the new id to the rssi objects
for(let rssi of reading.rssis)
rssi.reading_id = new_id;
// Insert the RSSIs into the database
this.RSSIRepo.add(...reading.rssis);
}
iterate() {
return this.db.prepare(`SELECT * FROM readings`).iterate();
}
}
export default ReadingRepo;