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-05-29 10:35:10 +00:00
|
|
|
if(typeof this.query_insert == "undefined")
|
|
|
|
this.query_insert = this.db.prepare(`INSERT INTO readings (
|
|
|
|
id,
|
|
|
|
lat, long,
|
2019-07-09 16:31:08 +00:00
|
|
|
data_rate, code_rate
|
2019-05-29 10:35:10 +00:00
|
|
|
) VALUES (
|
|
|
|
:id,
|
2019-07-09 13:05:42 +00:00
|
|
|
:latitude,
|
|
|
|
:longitude,
|
2019-07-09 16:31:08 +00:00
|
|
|
:data_rate, :code_rate
|
2019-05-29 10:35:10 +00:00
|
|
|
)`);
|
|
|
|
|
2019-07-10 11:21:38 +00:00
|
|
|
let new_id = this.insert_query.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;
|