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() {
|
||||
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){
|
||||
var postEvent = req.body.postEvent;
|
||||
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);
|
||||
|
||||
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON) VALUES (?)");
|
||||
stmt.run(JSON.stringify(req.body, null, 4));
|
||||
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON, coreid, published_at) VALUES (?, ?, ?)");
|
||||
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();
|
||||
//res.send(JSON.stringify(req.body, null, 4));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user