This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin; | |
| //------update campgrounds | |
| alter table campgrounds | |
| add column updated_at timestamp; | |
| update campgrounds | |
| set updated_at=now(); | |
| alter table campgrounds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var onionrm = require('onionrm'); | |
| var express = require('express'); | |
| var openDb = require('./database.js'); | |
| var app = express(); | |
| app.get('/api/updates/:model', function (req, res) { | |
| var filter = { | |
| updated_at: onionrm.gte(req.query.timestamp) | |
| }; | |
| openDb(function(err, models, closeDb){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var onionrm = require('onionrm'); | |
| var express = require('express'); | |
| var openDb = require('./database.js'); | |
| var app = express(); | |
| app.get('/api/updates/campgrounds', function (req, res) { | |
| var filter = { | |
| updated_at: onionrm.gte(req.query.timestamp) | |
| }; | |
| openDb(function(err, models, closeDb){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| select * | |
| from campgrounds | |
| where updated_at >= ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| models.Campground.find({updated_at: onionrm.gte(timestamp)}, function(err, campgrounds){ | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| insert into campgrounds(name, latitude, longitude, rating, address, city, state, zip_code) values ('River Gaze Fairgrounds', -87.6548200268318, 118.498275771141, 1, '9073 Ann Street', 'Anytown', 'MA', '70323'); | |
| insert into campgrounds(name, latitude, longitude, rating, address, city, state, zip_code) values ('River Memorial Park', 49.5609541285241, -82.8582183796971, 4, '6629 13th Street', 'Anytown', 'NJ', '60857'); | |
| insert into campgrounds(name, latitude, longitude, rating, address, city, state, zip_code) values ('Farm Gaze Escape', -20.7519408129825, 153.213485277029, 1.5, '8383 Willow Drive', 'Anytown', 'ID', '62333'); | |
| insert into campgrounds(name, latitude, longitude, rating, address, city, state, zip_code) values ('Mountain Escape Villa', -66.4780486909743, 128.33472487545, 1.5, '2156 Route 29', 'Anytown', 'PR', '71293'); | |
| insert into campgrounds(name, latitude, longitude, rating, address, city, state, zip_code) values ('Rockwell Campground', -17.9728860687619, 177.951461968511, 3.5, '9414 West Street', 'A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var app = express(); | |
| var fs = require("fs"); | |
| var md5 = require('md5'); | |
| app.get('/api/updates', function (req, res) { | |
| fs.readFile("./generated/database.db", function(err, file) { | |
| var checksum = md5(file); | |
| if(checksum == req.query.checksum){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (IBAction)doApplyUpdate:(id)sender { | |
| [[Sync defaultWorker] applyOutstandingUpdates]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table campgrounds ( | |
| id int4 primary key not null, | |
| name text not null, | |
| latitude float8, | |
| longitude float8, | |
| rating numeric, | |
| address text, | |
| city text, | |
| state text, | |
| zip_code text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function(next){ | |
| var sql = "insert into campgrounds (id, name, latitude, longitude, rating, address, city, state, zip_code) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; | |
| models.Campground.find(function(err, campgrounds){ | |
| async.eachSeries(campgrounds, function(c, next){ | |
| sqliteDb.run(sql, [c.id, c.name, c.latitude, c.longitude, c.rating, c.address, c.city, c.state, c.zip_code], next) | |
| }, next); | |
| }); | |
| } |