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.
 
 
 

105 lines
2.6 KiB

import "../config/globals";
import moment from "moment";
function transaction(db, query, values) {
console.log("inserting values");
db.transaction((tx) => {
tx.executeSql(
query,
values,
(_, results) => {
console.debug("Values inserted successfully" + results.rowsAffected);
},
(_, err) => {
console.debug("Error while inserting values: " + JSON.stringify(err));
}
);
});
}
function insertFloodZone({ images, description, passable, location }) {
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
}
const values = [
description,
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
parseInt(passable),
];
transaction(global.userDataBase, query, values);
}
function insertPluviometerData({ pluviometer, images, dateTime, time, location }) {
const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
}
const values = [
moment(dateTime).format("DD/MM/YYYY") +" | "+ moment(time).format("HH:MM"),
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
parseFloat(pluviometer),
];
transaction(global.userDataBase, query, values);
}
function insertRainData({ images, description, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
}
const values = [
parseInt(rain),
description,
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
];
console.log(values);
transaction(global.userDataBase, query, values);
}
function insertRiverData({ images, description, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
return;
}
const values = [
parseInt(riverScale),
description,
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
];
console.log(values);
transaction(global.userDataBase, query, values);
}
export {
insertFloodZone,
insertPluviometerData,
insertRainData,
insertRiverData,
};