My LoRaWAN Signal Mapping MSc summer project. This is a copy of the actual repository with personal information removed.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

"use strict";
class GatewayRepo {
constructor({ database }) {
this.db = database;
add(...gateways) {
const statement = this.db.prepare(`INSERT INTO gateways (
latitude, longitude,
:latitude, :longitude,
for(let gateway of gateways);
* Determines whether a gateway exists in the dayabase with the given name.
* @param {string} id The id of the gateway.
* @return {bool} Whether a gateway with the given name exists in the database.
exists(id) {
// Note that normally a count wouldn't be appropriate here just to test for existence, but it's ok because it's guaranteed that there will only ever be a single entry with a given id.
let statement = this.db.prepare(`SELECT COUNT(id) AS count
FROM gateways
WHERE id = :id`);
let count = statement.get({ id }).count;
return count > 0;
get_by_id(id) {
return this.db.prepare(`SELECT * FROM gateways WHERE id = :id`).get({ id });
* Iterates over all the gateways in the table.
* TODO: Use Symbol.iterator here?
* @return {Generator} A generator that can be used with for..of
iterate() {
return this.db.prepare(`SELECT * FROM gateways`).iterate();
export default GatewayRepo;