2019-05-22 11:28:57 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class ReadingRepo {
|
2019-07-09 13:05:42 +00:00
|
|
|
constructor({ database, RSSIRepo }) {
|
|
|
|
this.db = database;
|
|
|
|
this.RSSIRepo = RSSIRepo;
|
2019-05-22 17:04:46 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 21:48:51 +00:00
|
|
|
add(reading) {
|
2019-07-10 13:32:58 +00:00
|
|
|
const statement = this.db.prepare(`INSERT INTO readings (
|
|
|
|
id,
|
|
|
|
latitude, longitude,
|
|
|
|
data_rate, code_rate
|
|
|
|
) VALUES (
|
|
|
|
:id,
|
|
|
|
:latitude,
|
|
|
|
:longitude,
|
|
|
|
:data_rate, :code_rate
|
|
|
|
);`);
|
2019-05-29 10:35:10 +00:00
|
|
|
|
2019-07-10 13:32:58 +00:00
|
|
|
let new_id = statement.run(reading).lastInsertRowid;
|
2019-05-29 10:35:10 +00:00
|
|
|
|
2019-07-10 11:21:38 +00:00
|
|
|
// 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
|
2019-05-29 10:35:10 +00:00
|
|
|
this.RSSIRepo.add(...reading.rssis);
|
|
|
|
}
|
|
|
|
|
|
|
|
iterate() {
|
|
|
|
return this.db.prepare(`SELECT * FROM readings`).iterate();
|
2019-05-22 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReadingRepo;
|