Skip to content

Instantly share code, notes, and snippets.

begin;
//------update campgrounds
alter table campgrounds
add column updated_at timestamp;
update campgrounds
set updated_at=now();
alter table campgrounds
@jwhitehorn
jwhitehorn / api.js
Last active February 23, 2018 18:53
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){
@jwhitehorn
jwhitehorn / api.js
Last active December 25, 2017 20:11
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){
select *
from campgrounds
where updated_at >= ?
models.Campground.find({updated_at: onionrm.gte(timestamp)}, function(err, campgrounds){
});
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
@jwhitehorn
jwhitehorn / api.js
Last active December 30, 2017 20:54
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){
- (IBAction)doApplyUpdate:(id)sender {
[[Sync defaultWorker] applyOutstandingUpdates];
}
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
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);
});
}