diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000..e62ba31 --- /dev/null +++ b/.tern-project @@ -0,0 +1,9 @@ +{ + "ecmaVersion": 8, + "libs": [], + "loadEagerly": [], + "dontLoad": [], + "plugins": { + "doc_comment": true + } +} \ No newline at end of file diff --git a/server/Helpers/Database.mjs b/server/Helpers/Database.mjs index debbdda..3a80b72 100644 --- a/server/Helpers/Database.mjs +++ b/server/Helpers/Database.mjs @@ -1,16 +1,18 @@ "use strict"; -import Database from 'batter-sqlite3'; +import fs from 'fs'; +import Database from 'better-sqlite3'; -var db_connection = null; +var db = null; -function init(filename, options) { - db_connection = new Database(filename, options); +async function init(filename, options) { + db = new Database(filename, options); + db.exec(await fs.promises.readFile("../db_template.sql", "utf8")); } -function get_connection() { - return db_connection; +function get_instance() { + return db; } -export { init, get_connection }; +export { init, get_instance }; diff --git a/server/Models/RSSI.mjs b/server/Models/RSSI.mjs index f21ce21..7032eda 100644 --- a/server/Models/RSSI.mjs +++ b/server/Models/RSSI.mjs @@ -2,7 +2,7 @@ /** * The received signal strength of a message from a single gateway. - * @param {string} id The id of this rssi measurement. + * @param {number} id The id of this rssi measurement. * @param {number} gateway_id The id of this gateway. * @param {number} rssi The rssi measurement. */ diff --git a/server/Repos.SQLite/ReadingRepo.mjs b/server/Repos.SQLite/ReadingRepo.mjs index cea8dc4..c084f9c 100644 --- a/server/Repos.SQLite/ReadingRepo.mjs +++ b/server/Repos.SQLite/ReadingRepo.mjs @@ -1,8 +1,18 @@ "use strict"; +import { get_instance } from '../Helpers/Database.mjs'; + + class ReadingRepo { - constructor() { + constructor(in_RSSIRepo) { + this.db = get_instance(); + this.RSSIRepo = in_RSSIRepo; + this.insert_query = this.db.prepare("INSERT INTO readings") + } + + insert(reading) { + this.db. } } diff --git a/server/db_template.sql b/server/db_template.sql new file mode 100644 index 0000000..7cfb092 --- /dev/null +++ b/server/db_template.sql @@ -0,0 +1,25 @@ +CREATE TABLE readings IF NOT EXISTS ( + id INTEGER PRIMARY KEY, -- Random unique integer + lat FLOAT NOT NULL, -- Latitude component of GPS co-ordinates of reading + long FLOAT NOT NULL, -- Longitude component of GPS co-ordinates of reading, + data_rate_id INTEGER, -- The id of the data rate code in the data_rates table that describes the data rate at which the message was transmitted + code_rate TEXT, -- The coding rate at which the message was transmitted. FUTURE: This may need to be an INTEGER field - not sure + bit_rate INTEGER, -- The bit rate at which the message was transmitted +); +CREATE TABLE rssis IF NOT EXISTS ( + id INTEGER PRIMARY KEY, -- Random unique int + reading_id INTEGER, -- The id of the object in the readings table that this rssi measurement belongs to + gateway_id INTEGER, -- Gateway id that the RSSI was from + rssi FLOAT, -- The RSSI value itself + channel INTEGER -- The channel that the RSSI was received over. We might be able to use this to detect single-channel gateways +); +CREATE TABLE gateways IF NOT EXISTS ( + id TEXT PRIMARY KEY, -- The gateway s name + lat FLOAT, -- Latitude component of the claimed GPS co-ordinates of the gateway + long FLOAT -- Longitude component of the claimed GPS co-ordinates of the gateway + altitude FLOAT -- Claimed alitude of the gateway +); +CREATE TABLE data_rates IF NOT EXISTS ( + id INTEGER PRIMARY KEY, -- Random unique integer, + codename TEXT NOT NULL, +) diff --git a/server/package-lock.json b/server/package-lock.json index 0b2e368..4fc7126 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -4,6 +4,19 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/better-sqlite3": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/@types/better-sqlite3/-/better-sqlite3-5.4.0.tgz", + "integrity": "sha512-nzm7lJ7l3jBmGUbtkL8cdOMhPkN6Pw2IM+b0V7iIKba+YKiLrjkIy7vVLsBIVnd7+lgzBzrHsXZxCaFTcmw5Ow==", + "requires": { + "@types/integer": "*" + } + }, + "@types/integer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/integer/-/integer-1.0.0.tgz", + "integrity": "sha512-3viiRKLoSP2Qr78nMoQjkDc0fan4BgmpOyV1+1gKjE8wWXo3QQ78WItO6f9WuBf3qe3ymDYhM65oqHTOZ0rFxw==" + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", diff --git a/server/package.json b/server/package.json index ff1820c..959cdf5 100644 --- a/server/package.json +++ b/server/package.json @@ -19,6 +19,7 @@ "author": "Starbeamrainbowlabs", "license": "MPL-2.0", "dependencies": { + "@types/better-sqlite3": "^5.4.0", "better-sqlite3": "^5.4.0", "ttn": "^2.3.2" }