From d0357b30a434e4b179cd073fa725de96403710a1 Mon Sep 17 00:00:00 2001 From: Paul Williams Date: Sun, 5 May 2013 19:17:13 +0100 Subject: [PATCH 1/4] Fixed issue with csv node module deprecating fromPath in favour of from.path --- chap8-redis/pre_populate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chap8-redis/pre_populate.js b/chap8-redis/pre_populate.js index 6102830..182dc86 100644 --- a/chap8-redis/pre_populate.js +++ b/chap8-redis/pre_populate.js @@ -46,7 +46,7 @@ function trackLineCount() { */ function populateRedis() { csv(). - fromPath( tsvFileName, { delimiter: '\t', quote: '' }). + from.path( tsvFileName, { delimiter: '\t', quote: '' }). on('data', function(data, index) { var artist = data[2], From f34fb07959e21fb07abede4c77445ee83758fcc7 Mon Sep 17 00:00:00 2001 From: Paul Williams Date: Mon, 6 May 2013 13:41:01 +0100 Subject: [PATCH 2/4] changed csv parser event for record rather than data to support group_membership.tsv --- chap8-redis/pre_populate.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chap8-redis/pre_populate.js b/chap8-redis/pre_populate.js index 182dc86..9bd2457 100644 --- a/chap8-redis/pre_populate.js +++ b/chap8-redis/pre_populate.js @@ -47,15 +47,16 @@ function trackLineCount() { function populateRedis() { csv(). from.path( tsvFileName, { delimiter: '\t', quote: '' }). - on('data', function(data, index) { + on('record', function(record, index) { var - artist = data[2], - band = data[3], - roles = buildRoles(data[4]); + artist = record[2], + band = record[3], + roles = buildRoles(record[4]); if( band === '' || artist === '' ) { trackLineCount(); return true; - } + } + //console.log('#'+index+' '+JSON.stringify(record)); redis_client.sadd('band:' + band, artist); roles.forEach(function(role) { redis_client.sadd('artist:' + band + ':' + artist, role); From 826f274bb5e28b3745fde96fd6b4744791f0cbc0 Mon Sep 17 00:00:00 2001 From: Paul Williams Date: Mon, 6 May 2013 14:14:09 +0100 Subject: [PATCH 3/4] changed requests to use http.request rather than use deprecated httpClient --- chap8-redis/populate_couch.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/chap8-redis/populate_couch.js b/chap8-redis/populate_couch.js index 1a9c393..851c483 100644 --- a/chap8-redis/populate_couch.js +++ b/chap8-redis/populate_couch.js @@ -19,8 +19,7 @@ var http = require('http'), redis = require('redis'), - // database clients - couchClient = http.createClient(5984, 'localhost'), + // database client redisClient = redis.createClient(6379); /** @@ -62,11 +61,14 @@ function trackLineCount( increment ) { */ function postDoc( url, docsString, count ) { - var request = couchClient.request( - 'POST', - url, - { 'Content-Type' : 'application/json' }); - request.end( docsString ); + var request = http.request( + { hostname : 'localhost', + port: 5984, + path: url, + method: 'POST', + headers: { + 'Content-Type': 'application/json'} + }); request.on('response', function(response) { if(response.statusCode == 201) @@ -75,6 +77,8 @@ function postDoc( url, docsString, count ) { on('error', function(e) { console.log('postDoc Got error: ' + e.message); }); + request.write(docsString) + request.end(); }; /* @@ -95,7 +99,11 @@ function postDoc( url, docsString, count ) { function populateBands() { // First, create the couch database - couchClient.request('PUT', couchDBpath).end(); + http.request( + { hostname : 'localhost', + port: 5984, + path: couchDBpath, + method: 'PUT'}).end(); redisClient.keys('band:*', function(error, bandKeys) { totalBands = bandKeys.length; @@ -104,6 +112,7 @@ function populateBands() { bandsBatch = []; bandKeys.forEach(function(bandKey) { + console.log(bandKey); // substring of 'band:'.length gives us the band name var bandName = bandKey.substring(5); redisClient.smembers(bandKey, function(error, artists) { From 9e51d45c6b00cb6f5c98e918d8627ca9c0dc5a4d Mon Sep 17 00:00:00 2001 From: Paul Williams Date: Mon, 6 May 2013 14:17:16 +0100 Subject: [PATCH 4/4] removed debugging console.log --- chap8-redis/populate_couch.js | 1 - 1 file changed, 1 deletion(-) diff --git a/chap8-redis/populate_couch.js b/chap8-redis/populate_couch.js index 851c483..fb84e0e 100644 --- a/chap8-redis/populate_couch.js +++ b/chap8-redis/populate_couch.js @@ -112,7 +112,6 @@ function populateBands() { bandsBatch = []; bandKeys.forEach(function(bandKey) { - console.log(bandKey); // substring of 'band:'.length gives us the band name var bandName = bandKey.substring(5); redisClient.smembers(bandKey, function(error, artists) {