48 lines
872 B
JavaScript
48 lines
872 B
JavaScript
"use strict";
|
|
|
|
class RSSIRepo {
|
|
constructor({ database }) {
|
|
this.db = database;
|
|
}
|
|
|
|
add(...rssis) {
|
|
const statement = this.db.prepare(`INSERT INTO rssis (
|
|
id,
|
|
reading_id, gateway_id,
|
|
rssi, snr,
|
|
channel
|
|
) VALUES (
|
|
:id,
|
|
:reading_id, :gateway_id,
|
|
:rssi, :snr,
|
|
:channel
|
|
)`);
|
|
for(let rssi of rssis) {
|
|
// console.log(`Storing`, rssi);
|
|
statement.run(rssi);
|
|
}
|
|
}
|
|
|
|
iterate_gateway(gateway_id) {
|
|
return this.db.prepare(`SELECT
|
|
rssis.*,
|
|
readings.latitude,
|
|
readings.longitude
|
|
FROM rssis
|
|
JOIN readings ON rssis.reading_id = readings.id
|
|
WHERE gateway_id = :gateway_id`).iterate({
|
|
gateway_id
|
|
});
|
|
}
|
|
|
|
iterate() {
|
|
return this.db.prepare(`SELECT
|
|
rssis.*,
|
|
readings.latitude,
|
|
readings.longitude
|
|
FROM rssis
|
|
JOIN readings ON rssis.reading_id = readings.id`).iterate();
|
|
}
|
|
}
|
|
|
|
export default RSSIRepo;
|