Created
June 28, 2016 00:26
-
-
Save jwintersinger/900e41d72423f1b162cdb3d337924f2c to your computer and use it in GitHub Desktop.
This file contains 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 fetch_packages(db, on_done) { | |
// Your code goes here. You must return an array of objects that looks like | |
// this (which you can infer from looking at what fields we reference in | |
// index.html): | |
// | |
// [ { sent_on: '2016-06-27 14:31:03', | |
// due_on: '2016-06-28 08:00:00', | |
// received_on: null, | |
// shipper_name: 'Nils Olav', | |
// receiver_name: 'William Windsor', | |
// destination_address: 'Whipsnade Zoo, Whipsnade, England, Earth' }, | |
// { sent_on: '2016-06-27 14:31:03', | |
// due_on: '2016-06-28 08:00:00', | |
// received_on: null, | |
// shipper_name: 'Nils Olav', | |
// receiver_name: 'William Windsor', | |
// destination_address: 'Whipsnade Zoo, Whipsnade, England, Earth' } ] | |
// | |
// Hint: the easiest way to do this is with SQL joins. If you don't know how | |
// to use joins, you will have to issue multiple queries. | |
db.query( | |
'SELECT p.sent_on, p.due_on, p.received_on, c1.name shipper_name, c2.name receiver_name, ' + | |
'(a.street || ", " || a.city || ", " || a.country || ", " || a.planet) destination_address ' + | |
'FROM packages p ' + | |
'JOIN customers c1 ON c1.id = p.shipping_customer ' + | |
'JOIN customers c2 ON c2.id = p.receiving_customer ' + | |
'JOIN addresses a ON a.id = p.destination_address' | |
).spread(function(packages, metadata) { | |
on_done(packages); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment