Created
          August 15, 2015 03:13 
        
      - 
      
- 
        Save edmistond/63598dcc12423fb548b3 to your computer and use it in GitHub Desktop. 
  
    
      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 Promise = require('bluebird'); | |
| var Feedbin = Promise.promisifyAll(require('feedbinjs')); | |
| var _ = require('lodash'); | |
| var r = require('rethinkdb'); | |
| var connection = null; | |
| var fb = null; | |
| r.connect({host: 'localhost', port: 28015}) | |
| .then(function(conn) { connection = conn; }) | |
| .then(function() { | |
| return r.db('feedbin').tableList().run(connection); | |
| }) | |
| .then(function(tables) { | |
| if(!_.some(tables, function(t) { return t === 'subscriptions'; })) { | |
| console.log('creating subscriptions table!'); | |
| r.db('feedbin').tableCreate('subscriptions').run(connection); | |
| } | |
| return tables; | |
| }) | |
| .then(function(tables) { | |
| if(!_.some(tables, function(t) { return t === 'tags'; })) { | |
| console.log('creating tags table!'); | |
| return r.db('feedbin').tableCreate('tags').run(connection); | |
| } | |
| }) | |
| .then(function() { return console.log('connected to rethink and finished setup'); }) | |
| .then(function() { | |
| var deferred = Promise.pending(); | |
| fb = new Feedbin('user', 'pass', 'http://localhost:3002', function(err) { | |
| if (err) { | |
| deferred.reject(); | |
| } | |
| deferred.resolve(); | |
| }); | |
| return deferred.promise; | |
| }) | |
| .then(function() { | |
| return r.db('feedbin').table('subscriptions').insert(fb.allSubs).run(connection); | |
| }) | |
| .then(function(result) { | |
| console.log('inserted subscription data!'); | |
| console.log(result); | |
| }) | |
| .then(function() { | |
| return r.db('feedbin').table('tags').insert(fb.allTags).run(connection); | |
| }) | |
| .then(function() { | |
| console.log('disconnecting from rethinkdb'); | |
| connection.close(); | |
| }) | |
| .then(function() { process.exit(0); }) | |
| .catch(function(e) { | |
| console.log('oops, something bad happened.'); | |
| console.dir(e); | |
| process.exit(1); | |
| }) | |
| .done(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment