Giter Club home page Giter Club logo

agilemoviedb's People

Contributors

ericnograles avatar grales avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

handleror

agilemoviedb's Issues

Adapting your seeds.js to sails0.10.x

Hi, I came across your project while searching for strategies for seeding my sails.js project with data it needs. I am using Sails 0.10.x.

I've followed your example just fine (Thanks for the blog btw, it was educational), making changes where needed for Sails 0.10.x, but I am having issues with the following line

new Movie({ adapters: { mongo: mongoAdapter }}, function(err, collection) {

I just can't work out what needs to be there.

My config/connections.js looks like:

module.exports.connections = {
  development: {
    adapter  : 'sails-mongo',
    host     : 'localhost',
    port     : 27017,
    user     : 'myuser',
    password : 'mypass',
    database : 'mydb'
  }
};

and my data/seeds.js looks like

var _ = require("lodash"),
    Waterline = require("waterline"),
    connectionsConfig = require("../config/connections"),
    dbEnv = process.env.NODE_ENV || 'development',
    connection = connectionsConfig.connections[dbEnv],
    mongoAdapter = require(connection.adapter),
    Promise = require("promise"), mongoUrl;

console.log("connecting with ", connection);

// Match our config
mongoUrl = "mongodb://" +
            connection.user + ":" + connection.password + "@" +
            connection.host + ":" + connection.port + "/" +
            connection.database;

mongoAdapter.database = connection.database;
mongoAdapter.host =     connection.host;
mongoAdapter.port =     connection.port;
mongoAdapter.user =     connection.user;
mongoAdapter.password = connection.password;
mongoAdapter.config = {
  url: mongoUrl
};

/**
 * Seeds locations in a promise-y way
 */
var seedLocation = function() {
  console.log("seeding Locations");

  var LocationModel = require("../api/models/Location"),
      locationData = require("./locations.json");

  console.log("LocationModel", LocationModel);
  console.log("locationData", locationData.length);

  return new Promise(
    function(fulfill, reject) {
      // Seed Location Data from our JSON
      LocationModel.adapter = dbEnv;
      var Location = Waterline.Collection.extend(LocationModel);

      // Invoke Waterline
      new Location({ adapters: mongoAdapter }, function(err, collection) {
        if (err){
          console.error("There was a problem initializing the Location collection.");
        } else {
          // First nuke all existing Locations
          collection.destroy().done(function(err, deletedLocations) {
            console.log("Successfully deleted " + deletedLocations.length + " Locations!");
            collection.createEach(locationData, function(err, models) {
              if (err || _.isUndefined(models)) {
                console.log("Could not create Location collection!");
                fulfill();
              } else {
                console.log("Successfully inserted Locations");
                collection.find().done(function(err, existingLocations) {
                  fulfill(existingLocations);
                });
              }
            });
          });
        }
      });
    }
  );
};

// Node.js: fulfilling more promises than all politicians combined in history
seedLocation().then(function(locations) {
  console.log("Seeded" + locations.length + " locations");
  process.exit();
}, function(err){
  console.log("Seeding failed", err.stack);
});

The error I get is

Seeding failed TypeError: Cannot read property 'undefined' of undefined
    at Core._initialize (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/core/index.js:70:47)
    at module.exports (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/core/index.js:50:20)
    at module.exports (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/collection/index.js:44:8)
    at new child (/Users/dave/src/myproject/node_modules/waterline/lib/waterline/utils/extend.js:17:39)
    at /Users/dave/src/myproject/data/seeds.js:45:32
    at new Promise (/Users/dave/src/myproject/node_modules/promise/index.js:42:5)
    at seedLocation (/Users/dave/src/myproject/data/seeds.js:38:10)
    at Object.<anonymous> (/Users/dave/src/myproject/data/seeds.js:71:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

I am using waterline version 0.10.0-rc9 and sails 0.10.0-rc8

cheers and thanks in advance

dave

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.