Interim commit, change db insert to include default fields from POST data. server.js runs under node but havent tested with particle yet.
This commit is contained in:
parent
c5a3c152db
commit
68256ab8e8
19
server.js
19
server.js
@ -18,7 +18,14 @@ var db = new sqlite3.Database(file);
|
|||||||
|
|
||||||
db.serialize(function() {
|
db.serialize(function() {
|
||||||
if(!exists) {
|
if(!exists) {
|
||||||
db.run("CREATE TABLE Alerts (OrigJSON TEXT)");
|
db.run(
|
||||||
|
"CREATE TABLE Alerts (" +
|
||||||
|
"origJSON TEXT," +
|
||||||
|
"coreId TEXT," +
|
||||||
|
"locationDesc TEXT," +
|
||||||
|
"status TEXT," +
|
||||||
|
"published_at TEXT)"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,11 +40,15 @@ app.get('/', function(req, res){
|
|||||||
app.post('/', function(req, res){
|
app.post('/', function(req, res){
|
||||||
var postEvent = req.body.postEvent;
|
var postEvent = req.body.postEvent;
|
||||||
var source = req.body.source;
|
var source = req.body.source;
|
||||||
console.log("Post event = "+postEvent+", source is "+source);
|
//console.log("Post event = "+postEvent+", source is "+source);
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
|
|
||||||
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON) VALUES (?)");
|
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON, coreid, published_at) VALUES (?, ?, ?)");
|
||||||
stmt.run(JSON.stringify(req.body, null, 4));
|
stmt.run(
|
||||||
|
JSON.stringify(req.body, null, 4),
|
||||||
|
JSON.stringify(req.body.coreid, null, 4),
|
||||||
|
JSON.stringify(req.body.published_at, null, 4)
|
||||||
|
);
|
||||||
stmt.finalize();
|
stmt.finalize();
|
||||||
//res.send(JSON.stringify(req.body, null, 4));
|
//res.send(JSON.stringify(req.body, null, 4));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user