Skip to content

Commit

Permalink
Upgraded all dependencies. Fixed used of gcloud.datastore due to upgr…
Browse files Browse the repository at this point in the history
…ading gcloud.
  • Loading branch information
jmdobry committed Apr 7, 2016
1 parent a1d3ffa commit 8f81f43
Show file tree
Hide file tree
Showing 37 changed files with 258 additions and 288 deletions.
2 changes: 1 addition & 1 deletion 1-hello-world/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var app = express();

// [START hello_world]
// Say hello!
app.get('/', function(req, res) {
app.get('/', function (req, res) {
res.status(200).send('Hello, world!');
});
// [END hello_world]
Expand Down
15 changes: 7 additions & 8 deletions 2-structured-data/books/model-cloudsql.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var extend = require('lodash').assign;
var mysql = require('mysql');

module.exports = function(config) {
module.exports = function (config) {

function getConnection() {
return mysql.createConnection(extend({
Expand All @@ -30,7 +30,7 @@ module.exports = function(config) {
var connection = getConnection();
connection.query(
'SELECT * FROM `books` LIMIT ? OFFSET ?', [limit, token],
function(err, results) {
function (err, results) {
if (err) { return cb(err); }
var hasMore = results.length === limit ? token + results.length : false;
cb(null, results, hasMore);
Expand All @@ -43,7 +43,7 @@ module.exports = function(config) {
// [START create]
function create(data, cb) {
var connection = getConnection();
connection.query('INSERT INTO `books` SET ?', data, function(err, res) {
connection.query('INSERT INTO `books` SET ?', data, function (err, res) {
if (err) { return cb(err); }
read(res.insertId, cb);
});
Expand All @@ -54,7 +54,7 @@ module.exports = function(config) {
function read(id, cb) {
var connection = getConnection();
connection.query(
'SELECT * FROM `books` WHERE `id` = ?', id, function(err, results) {
'SELECT * FROM `books` WHERE `id` = ?', id, function (err, results) {
if (err) { return cb(err); }
if (!results.length) {
return cb({
Expand All @@ -71,7 +71,7 @@ module.exports = function(config) {
function update(id, data, cb) {
var connection = getConnection();
connection.query(
'UPDATE `books` SET ? WHERE `id` = ?', [data, id], function(err) {
'UPDATE `books` SET ? WHERE `id` = ?', [data, id], function (err) {
if (err) { return cb(err); }
read(id, cb);
});
Expand All @@ -95,7 +95,6 @@ module.exports = function(config) {
};
};


if (!module.parent) {
var prompt = require('prompt');
prompt.start();
Expand All @@ -104,7 +103,7 @@ if (!module.parent) {
'Running this script directly will allow you to initialize your mysql ' +
'database.\n This script will not modify any existing tables.\n');

prompt.get(['host', 'user', 'password'], function(err, result) {
prompt.get(['host', 'user', 'password'], function (err, result) {
if (err) { return; }
createSchema(result);
});
Expand All @@ -129,7 +128,7 @@ function createSchema(config) {
'`createdBy` VARCHAR(255) NULL, ' +
'`createdById` VARCHAR(255) NULL, ' +
'PRIMARY KEY (`id`));',
function(err) {
function (err) {
if (err) { throw err; }
console.log('Successfully created schema');
connection.end();
Expand Down
23 changes: 7 additions & 16 deletions 2-structured-data/books/model-datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@

var gcloud = require('gcloud');


module.exports = function(config) {
module.exports = function (config) {

// [START config]
var ds = gcloud.datastore.dataset(config.gcloud);
var ds = gcloud.datastore(config.gcloud);
var kind = 'Book';
// [END config]


// Translates from Datastore's entity format to
// the format expected by the application.
//
Expand All @@ -45,7 +43,6 @@ module.exports = function(config) {
return obj.data;
}


// Translates from the application's format to the datastore's
// extended entity property format. It also handles marking any
// specified properties as non-indexed. Does not translate the key.
Expand All @@ -72,7 +69,7 @@ module.exports = function(config) {
function toDatastore(obj, nonIndexed) {
nonIndexed = nonIndexed || [];
var results = [];
Object.keys(obj).forEach(function(k) {
Object.keys(obj).forEach(function (k) {
if (obj[k] === undefined) { return; }
results.push({
name: k,
Expand All @@ -83,7 +80,6 @@ module.exports = function(config) {
return results;
}


// Lists all books in the Datastore sorted alphabetically by title.
// The ``limit`` argument determines the maximum amount of results to
// return per page. The ``token`` argument allows requesting additional
Expand All @@ -95,15 +91,14 @@ module.exports = function(config) {
.order('title')
.start(token);

ds.runQuery(q, function(err, entities, nextQuery) {
ds.runQuery(q, function (err, entities, nextQuery) {
if (err) { return cb(err); }
var hasMore = entities.length === limit ? nextQuery.startVal : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
// [END list]


// Creates a new book or updates an existing book with new data. The provided
// data is automatically translated into Datastore format. The book will be
// queued for background processing.
Expand All @@ -123,18 +118,17 @@ module.exports = function(config) {

ds.save(
entity,
function(err) {
function (err) {
data.id = entity.key.id;
cb(err, err ? null : data);
}
);
}
// [END update]


function read(id, cb) {
var key = ds.key([kind, parseInt(id, 10)]);
ds.get(key, function(err, entity) {
ds.get(key, function (err, entity) {
if (err) { return cb(err); }
if (!entity) {
return cb({
Expand All @@ -146,16 +140,14 @@ module.exports = function(config) {
});
}


function _delete(id, cb) {
var key = ds.key([kind, parseInt(id, 10)]);
ds.delete(key, cb);
}


// [START exports]
return {
create: function(data, cb) {
create: function (data, cb) {
update(null, data, cb);
},
read: read,
Expand All @@ -164,5 +156,4 @@ module.exports = function(config) {
list: list
};
// [END exports]

};
8 changes: 4 additions & 4 deletions 2-structured-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"gcloud": "^0.28.0",
"gcloud": "^0.30.2",
"jade": "^1.11.0",
"kerberos": "^0.0.18",
"lodash": "^4.5.1",
"mongodb": "^2.1.7",
"kerberos": "^0.0.19",
"lodash": "^4.8.2",
"mongodb": "^2.1.15",
"mysql": "^2.10.2",
"prompt": "^1.0.0"
},
Expand Down
14 changes: 7 additions & 7 deletions 3-binary-data/books/model-cloudsql.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var extend = require('lodash').assign;
var mysql = require('mysql');


module.exports = function(config) {
module.exports = function (config) {

function getConnection() {
return mysql.createConnection(extend({
Expand All @@ -31,7 +31,7 @@ module.exports = function(config) {
var connection = getConnection();
connection.query(
'SELECT * FROM `books` LIMIT ? OFFSET ?', [limit, token],
function(err, results) {
function (err, results) {
if (err) { return cb(err); }
var hasMore = results.length === limit ? token + results.length : false;
cb(null, results, hasMore);
Expand All @@ -43,7 +43,7 @@ module.exports = function(config) {

function create(data, cb) {
var connection = getConnection();
connection.query('INSERT INTO `books` SET ?', data, function(err, res) {
connection.query('INSERT INTO `books` SET ?', data, function (err, res) {
if (err) { return cb(err); }
read(res.insertId, cb);
});
Expand All @@ -54,7 +54,7 @@ module.exports = function(config) {
function read(id, cb) {
var connection = getConnection();
connection.query(
'SELECT * FROM `books` WHERE `id` = ?', id, function(err, results) {
'SELECT * FROM `books` WHERE `id` = ?', id, function (err, results) {
if (err) { return cb(err); }
if (!results.length) {
return cb({
Expand All @@ -71,7 +71,7 @@ module.exports = function(config) {
function update(id, data, cb) {
var connection = getConnection();
connection.query(
'UPDATE `books` SET ? WHERE `id` = ?', [data, id], function(err) {
'UPDATE `books` SET ? WHERE `id` = ?', [data, id], function (err) {
if (err) { return cb(err); }
read(id, cb);
});
Expand Down Expand Up @@ -106,7 +106,7 @@ if (!module.parent) {
'Running this script directly will allow you to initialize your mysql ' +
'database.\n This script will not modify any existing tables.\n');

prompt.get(['host', 'user', 'password'], function(err, result) {
prompt.get(['host', 'user', 'password'], function (err, result) {
if (err) { return; }
createSchema(result);
});
Expand All @@ -132,7 +132,7 @@ function createSchema(config) {
'`createdBy` VARCHAR(255) NULL, ' +
'`createdById` VARCHAR(255) NULL, ' +
'PRIMARY KEY (`id`));',
function(err) {
function (err) {
if (err) { throw err; }
console.log('Successfully created schema');
connection.end();
Expand Down
14 changes: 7 additions & 7 deletions 3-binary-data/books/model-datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
var gcloud = require('gcloud');


module.exports = function(config) {
module.exports = function (config) {

var ds = gcloud.datastore.dataset(config.gcloud);
var ds = gcloud.datastore(config.gcloud);
var kind = 'Book';


Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function(config) {
function toDatastore(obj, nonIndexed) {
nonIndexed = nonIndexed || [];
var results = [];
Object.keys(obj).forEach(function(k) {
Object.keys(obj).forEach(function (k) {
if (obj[k] === undefined) { return; }
results.push({
name: k,
Expand All @@ -92,7 +92,7 @@ module.exports = function(config) {
.order('title')
.start(token);

ds.runQuery(q, function(err, entities, nextQuery) {
ds.runQuery(q, function (err, entities, nextQuery) {
if (err) { return cb(err); }
var hasMore = entities.length === limit ? nextQuery.startVal : false;
cb(null, entities.map(fromDatastore), hasMore);
Expand All @@ -118,7 +118,7 @@ module.exports = function(config) {

ds.save(
entity,
function(err) {
function (err) {
data.id = entity.key.id;
cb(err, err ? null : data);
}
Expand All @@ -128,7 +128,7 @@ module.exports = function(config) {

function read(id, cb) {
var key = ds.key([kind, parseInt(id, 10)]);
ds.get(key, function(err, entity) {
ds.get(key, function (err, entity) {
if (err) { return cb(err); }
if (!entity) {
return cb({
Expand All @@ -148,7 +148,7 @@ module.exports = function(config) {


return {
create: function(data, cb) {
create: function (data, cb) {
update(null, data, cb);
},
read: read,
Expand Down
8 changes: 4 additions & 4 deletions 3-binary-data/lib/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var gcloud = require('gcloud');


module.exports = function(gcloudConfig, cloudStorageBucket) {
module.exports = function (gcloudConfig, cloudStorageBucket) {

var storage = gcloud.storage(gcloudConfig);
var bucket = storage.bucket(cloudStorageBucket);
Expand Down Expand Up @@ -46,12 +46,12 @@ module.exports = function(gcloudConfig, cloudStorageBucket) {
var file = bucket.file(gcsname);
var stream = file.createWriteStream();

stream.on('error', function(err) {
stream.on('error', function (err) {
req.file.cloudStorageError = err;
next(err);
});

stream.on('finish', function() {
stream.on('finish', function () {
req.file.cloudStorageObject = gcsname;
req.file.cloudStoragePublicUrl = getPublicUrl(gcsname);
next();
Expand All @@ -71,7 +71,7 @@ module.exports = function(gcloudConfig, cloudStorageBucket) {
var multer = require('multer')({
inMemory: true,
fileSize: 5 * 1024 * 1024, // no larger than 5mb
rename: function(fieldname, filename) {
rename: function (fieldname, filename) {
// generate a unique filename
return filename.replace(/\W+/g, '-').toLowerCase() + Date.now();
}
Expand Down
8 changes: 4 additions & 4 deletions 3-binary-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"gcloud": "^0.28.0",
"gcloud": "^0.30.2",
"jade": "^1.11.0",
"kerberos": "^0.0.18",
"lodash": "^4.5.1",
"mongodb": "^2.1.7",
"kerberos": "^0.0.19",
"lodash": "^4.8.2",
"mongodb": "^2.1.15",
"multer": "^1.1.0",
"mysql": "^2.10.2",
"prompt": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion 4-auth/books/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

var express = require('express');

module.exports = function(model, images, oauth2) {
module.exports = function (model, images, oauth2) {

var router = express.Router();

Expand Down
Loading

0 comments on commit 8f81f43

Please sign in to comment.