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

36 lines
706 B
JavaScript

"use strict";
class ReadingRepo {
constructor({ database, RSSIRepo }) {
this.db = database;
this.RSSIRepo = RSSIRepo;
}
add(reading) {
const statement = this.db.prepare(`INSERT INTO readings (
id,
latitude, longitude,
data_rate, code_rate
) VALUES (
:id,
:latitude,
:longitude,
:data_rate, :code_rate
);`);
let new_id = statement.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;