1

I have the following in my Sailsjs config/adapter.js:

module.exports.adapters = {
  'default': 'postgres',

  postgres : {
   module   : 'sails-postgresql',
   host     : 'xxx.compute-1.amazonaws.com',
   port     : 5432,
   user     : 'xxx',
   password : 'xxx',
   database : 'xxx',
   ssl      : true,
   schema   : true

  }
};

And in models/Movie.js:

 Movie = {

  attributes: {
    tableName: 'movies.movies',
    title: 'string',
    link: 'string'
  }

};

module.exports = Movie;

In my controller:

Movie.query("SELECT * FROM movies.movies", function(err, movies) {
  console.log('movies', movies.rows);
});

movies.rows DOES return the correct data

However:

  Movie.find({ title: 'Frozen' }, function(err, movies) {
    console.log('movies', movies)
  });

movies returns an EMPTY ARRAY

So it seems all connections are good because the raw query works perfectly.

Could there be something I am doing wrong with setting up the Movie.find() or with models/Movie.js?

Does the tableName attribute not support postgresql schema_name.table_name?

1 Answer 1

2

First off, you need to move tableName out of attributes, since it's a class-level property. Second, sails-postgresql does have some (very undocumented) support for schemas, using the meta.schemaName option:

Movie = {

  tableName: 'movies',
  meta: {
     schemaName: 'movie'
  },

  attributes: {
    title: 'string',
    link: 'string'
  }

};

module.exports = Movie;

You can give that a try, and if it doesn't work, either move your table into the public schema, or nudge the author of the schemaName support for help.

Sign up to request clarification or add additional context in comments.

1 Comment

It keeps saving records under public schema, regardless of what schemaName is provided. Am I missing anything? User.create({name:'Diego'}).exec(function createCB(err, created){ console.log('Created user with name ' + created.name); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.